Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
dc42c2dd
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
349
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看板
提交
dc42c2dd
编写于
1月 15, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(composition api): readonly
上级
e4e4fe5b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
94 addition
and
3 deletion
+94
-3
pages/composition-api/reactivity/readonly/readonly.test.js
pages/composition-api/reactivity/readonly/readonly.test.js
+50
-0
pages/composition-api/reactivity/readonly/readonly.uvue
pages/composition-api/reactivity/readonly/readonly.uvue
+42
-1
pages/tab-bar/composition-api.uvue
pages/tab-bar/composition-api.uvue
+2
-2
未找到文件。
pages/composition-api/reactivity/readonly/readonly.test.js
0 → 100644
浏览文件 @
dc42c2dd
const
PAGE_PATH
=
'
/pages/composition-api/reactivity/readonly/readonly
'
describe
(
'
ref
'
,
()
=>
{
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
dataStr
=
await
page
.
$
(
'
#data-str
'
)
expect
(
await
dataStr
.
text
()).
toBe
(
'
data.str: default str
'
)
const
dataNum
=
await
page
.
$
(
'
#data-num
'
)
expect
(
await
dataNum
.
text
()).
toBe
(
'
data.num: 0
'
)
const
dataArr
=
await
page
.
$
(
'
#data-arr
'
)
expect
(
await
dataArr
.
text
()).
toBe
(
'
data.arr: ["a","b","c"]
'
)
const
readonlyDataStr
=
await
page
.
$
(
'
#readonly-data-str
'
)
expect
(
await
readonlyDataStr
.
text
()).
toBe
(
'
readonly data.str: default str
'
)
const
readonlyDataNum
=
await
page
.
$
(
'
#readonly-data-num
'
)
expect
(
await
readonlyDataNum
.
text
()).
toBe
(
'
readonly data.num: 0
'
)
const
readonlyDataArr
=
await
page
.
$
(
'
#readonly-data-arr
'
)
expect
(
await
readonlyDataArr
.
text
()).
toBe
(
'
readonly data.arr: ["a","b","c"]
'
)
const
updateDataBtn
=
await
page
.
$
(
'
#update-data-btn
'
)
await
updateDataBtn
.
tap
()
expect
(
await
dataStr
.
text
()).
toBe
(
'
data.str: new str
'
)
expect
(
await
dataNum
.
text
()).
toBe
(
'
data.num: 1
'
)
expect
(
await
dataArr
.
text
()).
toBe
(
'
data.arr: ["a","b","c","d"]
'
)
expect
(
await
readonlyDataStr
.
text
()).
toBe
(
'
readonly data.str: new str
'
)
expect
(
await
readonlyDataNum
.
text
()).
toBe
(
'
readonly data.num: 1
'
)
expect
(
await
readonlyDataArr
.
text
()).
toBe
(
'
readonly data.arr: ["a","b","c","d"]
'
)
const
updateReadonlyDataBtn
=
await
page
.
$
(
'
#update-readonly-data-btn
'
)
await
updateReadonlyDataBtn
.
tap
()
expect
(
await
dataStr
.
text
()).
toBe
(
'
data.str: new str
'
)
expect
(
await
dataNum
.
text
()).
toBe
(
'
data.num: 1
'
)
expect
(
await
dataArr
.
text
()).
toBe
(
'
data.arr: ["a","b","c","d"]
'
)
expect
(
await
readonlyDataStr
.
text
()).
toBe
(
'
readonly data.str: new str
'
)
expect
(
await
readonlyDataNum
.
text
()).
toBe
(
'
readonly data.num: 1
'
)
expect
(
await
readonlyDataArr
.
text
()).
toBe
(
'
readonly data.arr: ["a","b","c","d"]
'
)
})
}
else
{
it
(
'
other platform
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
}
})
\ No newline at end of file
pages/composition-api/reactivity/readonly/readonly.uvue
浏览文件 @
dc42c2dd
<template><view class="page">readonly</view></template>
\ No newline at end of file
<template>
<view class="page">
<text id="data-str" class="uni-common-mb">data.str: {{ data.str }}</text>
<text id="data-num" class="uni-common-mb">data.num: {{ data.num }}</text>
<text id="data-arr" class="uni-common-mb">data.arr: {{ data.arr}}</text>
<text id="readonly-data-str" class="uni-common-mb">readonly data.str: {{ readonlyData.str }}</text>
<text id="readonly-data-num" class="uni-common-mb">readonly data.num: {{ readonlyData.num }}</text>
<text id="readonly-data-arr" class="uni-common-mb">readonly data.arr: {{ readonlyData.arr}}</text>
<button id="update-data-btn" class="uni-common-mb" @click="updateData">update data</button>
<button id="update-readonly-data-btn" @click="updateReadonlyData">update readonly data</button>
</view>
</template>
<script setup>
type Data = {
str : string,
num : number,
arr : string[]
}
const data = reactive({
str: 'default str',
num: 0,
arr: ['a', 'b', 'c']
} as Data)
const readonlyData = readonly(data)
const updateData = () => {
data.str = 'new str'
data.num++
data.arr.push('d')
}
const updateReadonlyData = () => {
readonlyData.str = 'new readonly str'
readonlyData.num++
readonlyData.arr.push('e')
}
</script>
\ No newline at end of file
pages/tab-bar/composition-api.uvue
浏览文件 @
dc42c2dd
...
...
@@ -96,12 +96,12 @@
{
name: 'reactive',
url: 'reactive',
enable:
fals
e,
enable:
tru
e,
},
{
name: 'readonly',
url: 'readonly',
enable:
fals
e,
enable:
tru
e,
},
{
name: 'watch',
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录