Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
52073af8
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
350
Star
2
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello-uvue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
52073af8
编写于
8月 15, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 补充 props 使用引入类型示例
上级
9dc66aae
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
139 addition
and
66 deletion
+139
-66
pages/component-instance/props/props-composition.uvue
pages/component-instance/props/props-composition.uvue
+28
-21
pages/component-instance/props/props-options.uvue
pages/component-instance/props/props-options.uvue
+41
-33
pages/component-instance/props/props.test.js
pages/component-instance/props/props.test.js
+18
-12
pages/component-instance/props/reference-types-composition.uvue
...component-instance/props/reference-types-composition.uvue
+19
-0
pages/component-instance/props/reference-types-options.uvue
pages/component-instance/props/reference-types-options.uvue
+25
-0
pages/component-instance/props/types.uts
pages/component-instance/props/types.uts
+8
-0
未找到文件。
pages/component-instance/props/props-composition.uvue
浏览文件 @
52073af8
<template>
<view class="page">
<array-literal :str="str" :num="num" :bool="bool" :obj="obj" :arr="arr" />
<object-type str="str" :num="num" :bool="bool" :obj="obj" :arr="arr" />
<same-name-prop-default-value />
<props-with-defaults />
</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";
const str = 'str'
const num = 10
const bool = true
const obj = {age: 18}
const arr = ['a','b','c']
</script>
<template>
<view class="page">
<array-literal :str="str" :num="num" :bool="bool" :obj="obj" :arr="arr" />
<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 ReferenceTypes from './reference-types-composition.uvue'
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
pages/component-instance/props/props-options.uvue
浏览文件 @
52073af8
<template>
<view class="page">
<array-literal :str="str" :num="num" :bool="bool" :obj="obj" :arr="arr" />
<object-type str="str" :num="num" :bool="bool" :obj="obj" :arr="arr" />
<same-name-prop-default-value />
<props-with-defaults />
</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";
export default {
components: {
ArrayLiteral,
ObjectType,
SameNamePropDefaultValue,
PropsWithDefaults
},
data() {
return {
str: 'str',
num: 10,
bool: true,
obj: {age: 18},
arr: ['a','b','c']
}
},
}
</script>
<template>
<view class="page">
<array-literal :str="str" :num="num" :bool="bool" :obj="obj" :arr="arr" />
<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 ReferenceTypes from './reference-types-options.uvue'
export default {
components: {
ArrayLiteral,
ObjectType,
SameNamePropDefaultValue,
PropsWithDefaults,
ReferenceTypes
},
data() {
return {
str: 'str',
num: 10,
bool: true,
obj: { age: 18 },
arr: ['a', 'b', 'c']
}
},
}
</script>
\ No newline at end of file
pages/component-instance/props/props.test.js
浏览文件 @
52073af8
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
)
=>
{
const
arrayLiteralStr
=
await
page
.
$
(
'
#array-literal-str
'
)
expect
(
await
arrayLiteralStr
.
text
()).
toBe
(
'
str
'
)
const
arrayLiteralNum
=
await
page
.
$
(
'
#array-literal-num
'
)
expect
(
await
arrayLiteralNum
.
text
()).
toBe
(
'
10
'
)
const
arrayLiteralBool
=
await
page
.
$
(
'
#array-literal-bool
'
)
expect
(
await
arrayLiteralBool
.
text
()).
toBe
(
'
true
'
)
const
arrayLiteralObj
=
await
page
.
$
(
'
#array-literal-obj
'
)
expect
(
await
arrayLiteralObj
.
text
()).
toBe
(
'
{"age":18}
'
)
const
arrayLiteralArr
=
await
page
.
$
(
'
#array-literal-arr
'
)
expect
(
await
arrayLiteralArr
.
text
()).
toBe
(
'
["a","b","c"]
'
)
const
objectTypeStr
=
await
page
.
$
(
'
#object-type-str
'
)
expect
(
await
objectTypeStr
.
text
()).
toBe
(
'
str
'
)
const
objectTypeNum
=
await
page
.
$
(
'
#object-type-num
'
)
expect
(
await
objectTypeNum
.
text
()).
toBe
(
'
10
'
)
const
objectTypeBool
=
await
page
.
$
(
'
#object-type-bool
'
)
expect
(
await
objectTypeBool
.
text
()).
toBe
(
'
true
'
)
const
objectTypeObj
=
await
page
.
$
(
'
#object-type-obj
'
)
expect
(
await
objectTypeObj
.
text
()).
toBe
(
'
{"age":18}
'
)
const
objectTypeArr
=
await
page
.
$
(
'
#object-type-arr
'
)
expect
(
await
objectTypeArr
.
text
()).
toBe
(
'
["a","b","c"]
'
)
const
sameNamePropDefaultValueArr
=
await
page
.
$
(
'
#same-name-prop-default-value-arr
'
)
expect
(
await
sameNamePropDefaultValueArr
.
text
()).
toBe
(
'
[1,2,3]
'
)
...
...
@@ -41,19 +44,22 @@ 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
()
=>
{
page
=
await
program
.
reLaunch
(
OPTIONS_PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
await
test
(
page
)
});
it
(
'
props 组合式 API
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
COMPOSITION_PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
await
test
(
page
)
})
})
\ No newline at end of file
pages/component-instance/props/reference-types-composition.uvue
0 → 100644
浏览文件 @
52073af8
<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
pages/component-instance/props/reference-types-options.uvue
0 → 100644
浏览文件 @
52073af8
<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
pages/component-instance/props/types.uts
0 → 100644
浏览文件 @
52073af8
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录