提交 52073af8 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat: 补充 props 使用引入类型示例

上级 9dc66aae
......@@ -4,18 +4,25 @@
<object-type str="str" :num="num" :bool="bool" :obj="obj" :arr="arr" />
<same-name-prop-default-value />
<props-with-defaults />
<!-- #ifdef APP-ANDROID -->
<reference-types :list="[1,2,3]" />
<!-- #endif -->
<!-- #ifndef APP-ANDROID -->
<reference-types :list="['a','b','c']" />
<!-- #endif -->
</view>
</template>
<script setup lang="uts">
import ArrayLiteral from './array-literal-composition.uvue'
import ObjectType from "./object-type-composition.uvue";
import SameNamePropDefaultValue from "./same-name-prop-default-value-composition.uvue";
import PropsWithDefaults from "./props-with-defaults.uvue";
import ArrayLiteral from './array-literal-composition.uvue'
import ObjectType from "./object-type-composition.uvue";
import SameNamePropDefaultValue from "./same-name-prop-default-value-composition.uvue";
import PropsWithDefaults from "./props-with-defaults.uvue";
import ReferenceTypes from './reference-types-composition.uvue'
const str = 'str'
const num = 10
const bool = true
const obj = {age: 18}
const arr = ['a','b','c']
const str = 'str'
const num = 10
const bool = true
const obj = { age: 18 }
const arr = ['a', 'b', 'c']
</script>
\ No newline at end of file
......@@ -4,30 +4,38 @@
<object-type str="str" :num="num" :bool="bool" :obj="obj" :arr="arr" />
<same-name-prop-default-value />
<props-with-defaults />
<!-- #ifdef APP-ANDROID -->
<reference-types :list="[1,2,3]" />
<!-- #endif -->
<!-- #ifndef APP-ANDROID -->
<reference-types :list="['a','b','c']" />
<!-- #endif -->
</view>
</template>
<script lang="uts">
import ArrayLiteral from './array-literal-options.uvue'
import ObjectType from "./object-type-options.uvue";
import SameNamePropDefaultValue from "./same-name-prop-default-value-options.uvue";
import PropsWithDefaults from "./props-with-defaults.uvue";
import ArrayLiteral from './array-literal-options.uvue'
import ObjectType from "./object-type-options.uvue";
import SameNamePropDefaultValue from "./same-name-prop-default-value-options.uvue";
import PropsWithDefaults from "./props-with-defaults.uvue";
import ReferenceTypes from './reference-types-options.uvue'
export default {
export default {
components: {
ArrayLiteral,
ObjectType,
SameNamePropDefaultValue,
PropsWithDefaults
PropsWithDefaults,
ReferenceTypes
},
data() {
return {
str: 'str',
num: 10,
bool: true,
obj: {age: 18},
arr: ['a','b','c']
obj: { age: 18 },
arr: ['a', 'b', 'c']
}
},
}
}
</script>
\ No newline at end of file
const OPTIONS_PAGE_PATH = '/pages/component-instance/props/props-options'
const COMPOSITION_PAGE_PATH = '/pages/component-instance/props/props-composition'
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.includes('android')
describe('props', () => {
let page
const test = async (page) => {
......@@ -41,6 +44,9 @@ describe('props', () => {
expect(await propMsg.text()).toBe('hello')
const propLabels = await page.$('#prop-labels')
expect(await propLabels.text()).toBe('["a","b"]')
const referenceTypeList = await page.$('#reference-type-list')
expect(await referenceTypeList.text()).toBe(isAndroid ? '[1,2,3]' : '["a","b","c"]')
}
it('props 选项式 API', async () => {
......
<template>
<view>
<text class="mb-10 bold">reference types</text>
<text id="reference-type-list">{{ JSON.stringify(list) }}</text>
</view>
</template>
<script setup lang="uts">
import type { ReferenceTypesProps } from './types.uts'
const props = withDefaults(defineProps<ReferenceTypesProps>(), {
// #ifdef APP-ANDROID
list: [] as number[]
// #endif
// #ifndef APP-ANDROID
list: [] as string[]
// #endif
})
console.log('reference types props', props)
</script>
\ No newline at end of file
<template>
<view>
<text class="mb-10 bold">reference types</text>
<text id="reference-type-list">{{ JSON.stringify(list) }}</text>
</view>
</template>
<script lang="uts">
export default {
props: {
list: {
// #ifdef APP-ANDROID
type: Array as PropType<number[]>,
default: [] as number[]
// #endif
// #ifndef APP-ANDROID
type: Array as PropType<string[]>,
default: [] as string[]
// #endif
}
},
onReady() {
console.log('reference types props', this.$props)
}
}
</script>
\ No newline at end of file
export type ReferenceTypesProps = {
// #ifdef APP-ANDROID
list: number[]
// #endif
// #ifndef APP-ANDROID
list: string[]
// #endif
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册