Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
7607fb11
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
347
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看板
提交
7607fb11
编写于
12月 05, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(provide): 补充响应式 Object 示例及测试
上级
27bdbd15
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
62 addition
and
17 deletion
+62
-17
pages/composition/provide/component-for-inject-1.uvue
pages/composition/provide/component-for-inject-1.uvue
+30
-7
pages/composition/provide/provide.test.js
pages/composition/provide/provide.test.js
+22
-7
pages/composition/provide/provide.uvue
pages/composition/provide/provide.uvue
+10
-3
未找到文件。
pages/composition/provide/component-for-inject-1.uvue
浏览文件 @
7607fb11
...
...
@@ -7,19 +7,39 @@
<text class="uni-common-mt alias-provide-page-title"
>aliasProvidePageTitle: {{ aliasProvidePageTitle }}</text
>
<text class="uni-common-mt computed-title">computedTitle: {{ computedTitle }}</text>
<text class="uni-common-mt provide-page-str">providePageStr: {{ providePageStr }}</text>
<text class="uni-common-mt provide-page-num">providePageNum: {{ providePageNum }}</text>
<text class="uni-common-mt provide-page-bool">providePageBool: {{ providePageBool }}</text>
<text class="uni-common-mt computed-title"
>computedTitle: {{ computedTitle }}</text
>
<text class="uni-common-mt provide-data-obj-title"
>provideDataObj.title: {{ provideDataObj['title'] }}</text
>
<text class="uni-common-mt provide-data-obj-content"
>provideDataObj.content: {{ provideDataObj['content'] }}</text
>
<text class="uni-common-mt provide-page-str"
>providePageStr: {{ providePageStr }}</text
>
<text class="uni-common-mt provide-page-num"
>providePageNum: {{ providePageNum }}</text
>
<text class="uni-common-mt provide-page-bool"
>providePageBool: {{ providePageBool }}</text
>
<text class="uni-common-mt provide-page-object-title"
>providePageObject.title: {{ providePageObject['title'] }}</text
>
<text class="uni-common-mt provide-page-object-content"
>providePageObject.content: {{ providePageObject['content'] }}</text
>
<text class="uni-common-mt provide-page-arr">providePageArr: {{ providePageArr }}</text>
<text class="uni-common-mt provide-page-map">providePageMap: {{ providePageMap }}</text>
<text class="uni-common-mt provide-page-set">providePageSet: {{ providePageSet }}</text>
<text class="uni-common-mt provide-page-arr"
>providePageArr: {{ providePageArr }}</text
>
<text class="uni-common-mt provide-page-map"
>providePageMap: {{ providePageMap }}</text
>
<text class="uni-common-mt provide-page-set"
>providePageSet: {{ providePageSet }}</text
>
<text class="uni-common-mt test-inject-string-default-value"
>testInjectStringDefaultValue: {{ testInjectStringDefaultValue }}</text
>
...
...
@@ -50,6 +70,9 @@ export default {
type: String,
default: 'default computed title'
},
provideDataObj: {
type: Object as PropType<UTSJSONObject>,
},
providePageStr: {
type: String,
default: 'default provide page str'
...
...
pages/composition/provide/provide.test.js
浏览文件 @
7607fb11
...
...
@@ -16,25 +16,40 @@ describe('字面量方式创建 provide', () => {
it
(
'
alias
'
,
async
()
=>
{
const
aliasProvidePageTitleEl
=
await
page
.
$
(
'
.alias-provide-page-title
'
)
const
aliasProvidePageTitleText
=
await
aliasProvidePageTitleEl
.
text
()
// expect(aliasProvidePageTitleText).toBe(
// 'aliasProvidePageTitle: 字面量方式定义 provide page title'
// )
expect
(
aliasProvidePageTitleText
).
toBe
(
'
aliasProvidePageTitle:
default alias
provide page title
'
'
aliasProvidePageTitle:
字面量方式定义
provide page title
'
)
})
it
(
'
computed
'
,
async
()
=>
{
it
(
'
reactive data
'
,
async
()
=>
{
const
computedTitleEl
=
await
page
.
$
(
'
.computed-title
'
)
let
computedTitleText
=
await
computedTitleEl
.
text
()
expect
(
computedTitleText
).
toBe
(
'
computedTitle: 字面量方式定义 provide page title
'
)
const
changeTitleBtn
=
await
page
.
$
(
'
.change-title-btn
'
)
await
changeTitleBtn
.
tap
()
const
provideDataObjTitleEl
=
await
page
.
$
(
'
.provide-data-obj-title
'
)
let
provideDataObjTitleText
=
await
provideDataObjTitleEl
.
text
()
expect
(
provideDataObjTitleText
).
toBe
(
'
provideDataObj.title: data obj.title
'
)
const
provideDataObjContentEl
=
await
page
.
$
(
'
.provide-data-obj-content
'
)
let
provideDataObjContentText
=
await
provideDataObjContentEl
.
text
()
expect
(
provideDataObjContentText
).
toBe
(
'
provideDataObj.content: data obj.content
'
)
const
changeDataBtn
=
await
page
.
$
(
'
.change-data-btn
'
)
await
changeDataBtn
.
tap
()
computedTitleText
=
await
computedTitleEl
.
text
()
expect
(
computedTitleText
).
toBe
(
'
computedTitle: 字面量方式定义 provide page title changed
'
)
provideDataObjTitleText
=
await
provideDataObjTitleEl
.
text
()
expect
(
provideDataObjTitleText
).
toBe
(
'
provideDataObj.title: new title
'
)
provideDataObjContentText
=
await
provideDataObjContentEl
.
text
()
expect
(
provideDataObjContentText
).
toBe
(
'
provideDataObj.content: new content
'
)
})
it
(
'
string
'
,
async
()
=>
{
const
providePageStrEl
=
await
page
.
$
(
'
.provide-page-str
'
)
...
...
pages/composition/provide/provide.uvue
浏览文件 @
7607fb11
...
...
@@ -7,7 +7,7 @@
<button class="uni-common-mt" @click="goProvidePage2">
跳转函数方式定义 provide 示例
</button>
<button class="uni-common-mt change-
title-btn" @click="changeTitle">change title
</button>
<button class="uni-common-mt change-
data-btn" @click="changeData">change data
</button>
<ComponentForInject />
</view>
<!-- #ifdef APP -->
...
...
@@ -25,12 +25,17 @@ export default {
},
data(){
return {
title: '字面量方式定义 provide page title'
title: '字面量方式定义 provide page title',
obj: {
title: 'data obj.title',
content: 'data obj.content'
},
}
},
provide: {
providePageTitle: this.title,
computedTitle: computed<string>((): string => this.title),
provideDataObj: this.obj,
providePageStr: '字面量方式定义 provide page str',
providePageNum: 1,
providePageBool: true,
...
...
@@ -48,8 +53,10 @@ export default {
url: '/pages/composition/provide/provide-page2'
})
},
change
Title
() {
change
Data
() {
this.title = '字面量方式定义 provide page title changed'
this.obj['title'] = 'new title'
this.obj['content'] = 'new content'
}
},
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录