### Composition API Example
Source: https://github.com/dcloudio/uni-app/blob/uni-app-x/docs/vue/README.md
Demonstrates defining reactive data and methods using Vue 3's Composition API with the `setup` function. Use this for more flexible and concise component logic.
```vue
```
--------------------------------
### Configure and Start Lanhu MCP Service
Source: https://github.com/dcloudio/uni-app/blob/uni-app-x/docs/ai/use-ui-mcp.md
Set up the environment by running the setup script and then start the MCP service using Docker Compose. This step requires entering your Lanhu Cookie during setup.
```shell
bash setup-env.sh # macOS / Linux
# 或
setup-env.bat # Windows
```
```shell
docker-compose up -d
```
--------------------------------
### Get Device Info in uni-app
Source: https://github.com/dcloudio/uni-app/blob/uni-app-x/docs/api/get-device-info.md
This example demonstrates how to use the uni.getDeviceInfo() API to fetch device information and display it in a list. It handles potential null values and formats the output for display. Requires the APP platform.
```vue
{{item.label}}
{{item.value == "" ? "未获取" : item.value}}
```
--------------------------------
### Live Player Component Example
Source: https://github.com/dcloudio/uni-app/blob/uni-app-x/docs/component/live-player.md
This snippet demonstrates the usage of the live-player component, including template structure, script setup for state management, and event handlers for playback control and property configuration. It requires the 'ItemType' enum for configuring certain properties.
```uvue
API示例属性示例
```
--------------------------------
### Initiate Facial Recognition
Source: https://github.com/dcloudio/uni-app/blob/uni-app-x/docs/api/facial-recognition-meta-info.md
This snippet demonstrates how to initiate the facial recognition process. It includes input fields for name and ID card, and calls a cloud function to get meta information before starting the verification. Ensure you have the necessary uniCloud setup and that the environment supports this feature.
```vue
```
--------------------------------
### Directory Structure Example
Source: https://github.com/dcloudio/uni-app/blob/uni-app-x/docs/collocation/pagesjson.md
Illustrates a typical Uni-App project directory structure, showing the placement of pages, static assets, and configuration files.
```text
┌─pages
│ ├─index
│ │ └─index.uvue
│ └─login
│ └─login.uvue
├─static
├─main.uts
├─App.uvue
├─manifest.json
└─pages.json
```
--------------------------------
### Choose Media Configuration and UI
Source: https://github.com/dcloudio/uni-app/blob/uni-app-x/docs/api/choose-media.md
This snippet demonstrates the template and script setup for the `chooseMedia` API in a uni-app application. It includes UI elements for selecting media source, type, count, camera, and orientation, as well as a preview area for selected media.
```uvue
来源
{{sourceTypes[sourceTypeIndex].title}}
方式
{{(mediaTypes[mediaTypeIndex] as ChooseSource).title}}
数量限制
屏幕方向
{{orientationTypes[orientationTypeIndex].title}}
摄像头
{{cameraTypes[cameraTypeIndex].title}}点击预览{{mediaList.length}}/{{count}}
```
--------------------------------
### Uni-app(x) Page Test Case Example
Source: https://github.com/dcloudio/uni-app/blob/uni-app-x/docs/worktile/auto/quick-start.md
This example demonstrates how to write a basic test case for a uni-app(x) page using Jest. It shows how to get the page object, wait for elements, and assert text content.
```javascript
describe('test title', () => {
let page;
beforeAll(async () => {
page = await program.currentPage();
await page.waitFor(3000);
});
it('check page title', async () => {
const el = await page.$('.title'); // page.$(selector: string) 选择器(id、class、元素选择器)
const titleText = await el.text();
expect(titleText).toEqual('Hello');
});
});
```
--------------------------------
### Pull-down Refresh Example
Source: https://github.com/dcloudio/uni-app/blob/uni-app-x/docs/api/pull-down-refresh.md
This example demonstrates how to implement pull-down refresh functionality in a Uni-app application. It includes setup for scrollable views, data initialization, loading more data on scroll, and handling the pull-down refresh event. The code utilizes Vue.js syntax with Uni-app specific directives and lifecycle hooks.
```vue
list - {{num}}{{loadMoreText}}
```
--------------------------------
### View Help Information
Source: https://github.com/dcloudio/uni-app/blob/uni-app-x/docs/worktile/auto/hbuilderx-cli-uniapp-test.md
Displays command-line help for the uniapp.test CLI tool.
```bash
cli uniapp.test --help
```