Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
d63d99a9
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看板
提交
d63d99a9
编写于
1月 18, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(composition api): defineProps
上级
ab8dd6b7
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
140 addition
and
40 deletion
+140
-40
pages/composition-api/basic/define-props/array-literal.uvue
pages/composition-api/basic/define-props/array-literal.uvue
+10
-2
pages/composition-api/basic/define-props/define-props.test.js
...s/composition-api/basic/define-props/define-props.test.js
+55
-0
pages/composition-api/basic/define-props/define-props.uvue
pages/composition-api/basic/define-props/define-props.uvue
+23
-2
pages/composition-api/basic/define-props/object-literal.uvue
pages/composition-api/basic/define-props/object-literal.uvue
+30
-22
pages/composition-api/basic/define-props/type-props.uvue
pages/composition-api/basic/define-props/type-props.uvue
+22
-0
pages/composition-api/basic/define-props/type.uvue
pages/composition-api/basic/define-props/type.uvue
+0
-14
未找到文件。
pages/composition-api/basic/define-props/array-literal.uvue
浏览文件 @
d63d99a9
<template>
<view class="page">array literal</view>
<view>
<text class="bold uni-common-mb">array literal</text>
<text class="uni-common-mb" id="array-literal-str">str: {{ str }}</text>
<text class="uni-common-mb" id="array-literal-num">num: {{ num }}</text>
<text class="uni-common-mb" id="array-literal-bool">bool: {{ bool }}</text>
<text class="uni-common-mb" id="array-literal-arr">arr: {{ arr }}</text>
<text class="uni-common-mb" id="array-literal-obj">obj: {{ obj }}</text>
<text class="uni-common-mb" id="array-literal-fn">fn: {{ (fn as () => string)() }}</text>
</view>
</template>
<script setup>
const props = defineProps(['str', 'num', 'bool', 'arr', 'obj', 'func'])
defineProps(['str', 'num', 'bool', 'arr', 'obj', 'fn']);
</script>
pages/composition-api/basic/define-props/define-props.test.js
0 → 100644
浏览文件 @
d63d99a9
const
PAGE_PATH
=
'
/pages/composition-api/basic/define-props/define-props
'
describe
(
'
defineProps
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
android
'
))
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
basic
'
,
async
()
=>
{
const
arrayLiteralStr
=
await
page
.
$
(
'
#array-literal-str
'
)
expect
(
await
arrayLiteralStr
.
text
()).
toBe
(
'
str: default str
'
)
const
arrayLiteralNum
=
await
page
.
$
(
'
#array-literal-num
'
)
expect
(
await
arrayLiteralNum
.
text
()).
toBe
(
'
num: 0
'
)
const
arrayLiteralBool
=
await
page
.
$
(
'
#array-literal-bool
'
)
expect
(
await
arrayLiteralBool
.
text
()).
toBe
(
'
bool: false
'
)
const
arrayLiteralArr
=
await
page
.
$
(
'
#array-literal-arr
'
)
expect
(
await
arrayLiteralArr
.
text
()).
toBe
(
'
arr: ["a","b","c"]
'
)
const
arrayLiteralObj
=
await
page
.
$
(
'
#array-literal-obj
'
)
expect
(
await
arrayLiteralObj
.
text
()).
toBe
(
'
obj: {"arr":[1,2,3],"num":0,"str":"obj str"}
'
)
const
arrayLiteralFn
=
await
page
.
$
(
'
#array-literal-fn
'
)
expect
(
await
arrayLiteralFn
.
text
()).
toBe
(
'
fn: fn res
'
)
const
objectLiteralStr
=
await
page
.
$
(
'
#object-literal-str
'
)
expect
(
await
objectLiteralStr
.
text
()).
toBe
(
'
str: default str
'
)
const
objectLiteralNum
=
await
page
.
$
(
'
#object-literal-num
'
)
expect
(
await
objectLiteralNum
.
text
()).
toBe
(
'
num: 0
'
)
const
objectLiteralBool
=
await
page
.
$
(
'
#object-literal-bool
'
)
expect
(
await
objectLiteralBool
.
text
()).
toBe
(
'
bool: false
'
)
const
objectLiteralArr
=
await
page
.
$
(
'
#object-literal-arr
'
)
expect
(
await
objectLiteralArr
.
text
()).
toBe
(
'
arr: ["a","b","c"]
'
)
const
objectLiteralObj
=
await
page
.
$
(
'
#object-literal-obj
'
)
expect
(
await
objectLiteralObj
.
text
()).
toBe
(
'
obj: {"a":1}
'
)
const
objectLiteralFn
=
await
page
.
$
(
'
#object-literal-fn
'
)
expect
(
await
objectLiteralFn
.
text
()).
toBe
(
'
fn: fn res
'
)
const
typeStr
=
await
page
.
$
(
'
#type-str
'
)
expect
(
await
typeStr
.
text
()).
toBe
(
'
str: default str
'
)
const
typeNum
=
await
page
.
$
(
'
#type-num
'
)
expect
(
await
typeNum
.
text
()).
toBe
(
'
num: 0
'
)
const
typeBool
=
await
page
.
$
(
'
#type-bool
'
)
expect
(
await
typeBool
.
text
()).
toBe
(
'
bool: false
'
)
const
typeArr
=
await
page
.
$
(
'
#type-arr
'
)
expect
(
await
typeArr
.
text
()).
toBe
(
'
arr: ["a","b","c"]
'
)
const
typeObj
=
await
page
.
$
(
'
#type-obj
'
)
expect
(
await
typeObj
.
text
()).
toBe
(
'
obj: {"arr":[1,2,3],"num":0,"str":"obj str"}
'
)
const
typeFn
=
await
page
.
$
(
'
#type-fn
'
)
expect
(
await
typeFn
.
text
()).
toBe
(
'
fn: fn res
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/basic/define-props/define-props.uvue
浏览文件 @
d63d99a9
<template>
<view class="page"> defineProps </view>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view class="page">
<ArrayLiteral :str="str" :num='num' :bool='bool' :arr='arr' :obj='obj' :fn='fn' />
<ObjectLiteral :str="str" :num='num' :bool='bool' :arr='arr' :fn='fn' />
<TypeProps :str="str" :num='num' :bool='bool' :arr='arr' :obj='obj' :fn='fn' />
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script setup></script>
<script setup>
import ArrayLiteral from './array-literal.uvue';
import ObjectLiteral from './object-literal.uvue';
import TypeProps from './type-props.uvue';
const str = ref('default str')
const num = ref(0)
const bool = ref(false)
const arr = reactive(['a', 'b', 'c'])
const obj = reactive({ str: 'obj str', num: 0, arr: [1, 2, 3] })
const fn = () : string => 'fn res'
</script>
\ No newline at end of file
pages/composition-api/basic/define-props/object-literal.uvue
浏览文件 @
d63d99a9
<template>
<view class="page">object literal</view>
<view>
<text class="bold uni-common-mt uni-common-mb">object literal</text>
<text class="uni-common-mb" id="object-literal-str">str: {{ str }}</text>
<text class="uni-common-mb" id="object-literal-num">num: {{ num }}</text>
<text class="uni-common-mb" id="object-literal-bool">bool: {{ bool }}</text>
<text class="uni-common-mb" id="object-literal-arr">arr: {{ arr }}</text>
<text class="uni-common-mb" id="object-literal-obj">obj: {{ obj }}</text>
<text class="uni-common-mb" id="object-literal-fn">fn: {{ fn() }}</text>
</view>
</template>
<script setup>
const props =
defineProps({
defineProps({
str: String,
num: Number,
bool: {
...
...
@@ -12,15 +20,15 @@ const props = defineProps({
},
arr: {
type: Array as PropType<string[]>,
default: ()
: string[] => [] as string[]
default: ()
: string[] => [] as string[]
},
obj: {
type: Object as PropType<UTSJSONObject>,
default: ():
UTSJSONObject => ({ a: 1 })
default: () :
UTSJSONObject => ({ a: 1 })
},
func
: {
type: Function as PropType<() => void
>,
default: ():(() => void) => () => {}
fn
: {
type: Function as PropType<() => string
>,
default: () : string => ''
}
})
})
</script>
\ No newline at end of file
pages/composition-api/basic/define-props/type-props.uvue
0 → 100644
浏览文件 @
d63d99a9
<template>
<view>
<text class="bold uni-common-mt uni-common-mb">type props</text>
<text class="uni-common-mb" id="type-str">str: {{ str }}</text>
<text class="uni-common-mb" id="type-num">num: {{ num }}</text>
<text class="uni-common-mb" id="type-bool">bool: {{ bool }}</text>
<text class="uni-common-mb" id="type-arr">arr: {{ arr }}</text>
<text class="uni-common-mb" id="type-obj">obj: {{ obj }}</text>
<text id="type-fn">fn: {{ fn() }}</text>
</view>
</template>
<script setup>
defineProps<{
str : String,
num : Number,
bool : Boolean,
arr : PropType<string[]>,
obj : PropType<UTSJSONObject>,
fn : PropType<() => string>
}>()
</script>
\ No newline at end of file
pages/composition-api/basic/define-props/type.uvue
已删除
100644 → 0
浏览文件 @
ab8dd6b7
<template>
<view class="page">type</view>
</template>
<script setup>
// const props = defineProps<{
// str: String,
// num: Number,
// bool: Boolean,
// arr: Array as PropType<string[]>,
// obj: Object as PropType<UTSJSONObject>,
// func: Function as PropType<() => void>
// }>()
</script>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录