Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
389ac221
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
361
Star
3
Fork
8
代码
文件
提交
分支
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看板
提交
389ac221
编写于
8个月前
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(reactivity): readonly
上级
8466d59d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
55 deletion
+79
-55
pages/index/index.uvue
pages/index/index.uvue
+5
-0
pages/reactivity/core/readonly/readonly.test.js
pages/reactivity/core/readonly/readonly.test.js
+21
-21
pages/reactivity/core/readonly/readonly.uvue
pages/reactivity/core/readonly/readonly.uvue
+53
-34
未找到文件。
pages/index/index.uvue
浏览文件 @
389ac221
...
...
@@ -486,6 +486,11 @@ export default {
name: 'reactive',
url: 'reactive/reactive'
},
{
id: 'readonly',
name: 'readonly',
url: 'readonly/readonly'
},
]
}
] as Page[]
...
...
This diff is collapsed.
Click to expand it.
pages/reactivity/core/readonly/readonly.test.js
浏览文件 @
389ac221
const
PAGE_PATH
=
'
/pages/
composition-api/reactivity
/readonly/readonly
'
const
PAGE_PATH
=
'
/pages/
reactivity/core
/readonly/readonly
'
describe
(
'
ref
'
,
()
=>
{
let
page
=
null
...
...
@@ -8,37 +8,37 @@ describe('ref', () => {
})
it
(
'
basic
'
,
async
()
=>
{
const
dataStr
=
await
page
.
$
(
'
#data-str
'
)
expect
(
await
dataStr
.
text
()).
toBe
(
'
d
ata.str: d
efault str
'
)
expect
(
await
dataStr
.
text
()).
toBe
(
'
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"]
'
)
expect
(
await
dataNum
.
text
()).
toBe
(
'
0
'
)
const
dataArr
=
await
page
.
$
(
'
#data-arr
'
)
expect
(
await
dataArr
.
text
()).
toBe
(
'
["a","b","c"]
'
)
const
readonlyDataStr
=
await
page
.
$
(
'
#readonly-data-str
'
)
expect
(
await
readonlyDataStr
.
text
()).
toBe
(
'
readonly data.str:
default str
'
)
expect
(
await
readonlyDataStr
.
text
()).
toBe
(
'
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"]
'
)
expect
(
await
readonlyDataNum
.
text
()).
toBe
(
'
0
'
)
const
readonlyDataArr
=
await
page
.
$
(
'
#readonly-data-arr
'
)
expect
(
await
readonlyDataArr
.
text
()).
toBe
(
'
["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"]
'
)
expect
(
await
dataStr
.
text
()).
toBe
(
'
new str
'
)
expect
(
await
dataNum
.
text
()).
toBe
(
'
1
'
)
expect
(
await
dataArr
.
text
()).
toBe
(
'
["a","b","c","d"]
'
)
expect
(
await
readonlyDataStr
.
text
()).
toBe
(
'
new str
'
)
expect
(
await
readonlyDataNum
.
text
()).
toBe
(
'
1
'
)
expect
(
await
readonlyDataArr
.
text
()).
toBe
(
'
["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"]
'
)
expect
(
await
dataStr
.
text
()).
toBe
(
'
new str
'
)
expect
(
await
dataNum
.
text
()).
toBe
(
'
1
'
)
expect
(
await
dataArr
.
text
()).
toBe
(
'
["a","b","c","d"]
'
)
expect
(
await
readonlyDataStr
.
text
()).
toBe
(
'
new str
'
)
expect
(
await
readonlyDataNum
.
text
()).
toBe
(
'
1
'
)
expect
(
await
readonlyDataArr
.
text
()).
toBe
(
'
["a","b","c","d"]
'
)
})
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pages/reactivity/core/readonly/readonly.uvue
浏览文件 @
389ac221
<template>
<view class="page">
<text id="data-str" class="mb-10">data.str: {{ data.str }}</text>
<text id="data-num" class="mb-10">data.num: {{ data.num }}</text>
<text id="data-arr" class="mb-10">data.arr: {{ JSON.stringify(data.arr) }}</text>
<view class="flex justify-between flex-row mb-10">
<text>data.str:</text>
<text id="data-str">{{ data.str }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>data.num:</text>
<text id="data-num">{{ data.num }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>data.arr:</text>
<text id="data-arr">{{ JSON.stringify(data.arr) }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>readonly data.str:</text>
<text id="readonly-data-str">{{ readonlyData.str }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>readonly data.num:</text>
<text id="readonly-data-num">{{ readonlyData.num }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>readonly data.arr:</text>
<text id="readonly-data-arr">{{ JSON.stringify(readonlyData.arr) }}</text>
</view>
<
text id="readonly-data-str" class="mb-10">readonly data.str: {{ readonlyData.str }}</text
>
<text id="readonly-data-num" class="mb-10">readonly data.num: {{ readonlyData.num }}</text>
<
text id="readonly-data-arr" class="mb-10">readonly data.arr: {{ JSON.stringify(readonlyData.arr) }}</text
>
<button id="update-data-btn" class="mb-10" @click="updateData">update data</button>
<
button id="update-readonly-data-btn" @click="updateReadonlyData">update readonly data<
/button>
<
button id="update-data-btn" class="mb-10" @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[]
}
<script setup
lang="uts"
>
type Data = {
str : string,
num : number,
arr : string[]
}
const data = reactive({
str: 'default str',
num: 0,
arr: ['a', 'b', 'c']
} as Data)
const data = reactive({
str: 'default str',
num: 0,
arr: ['a', 'b', 'c']
} as Data)
const readonlyData = readonly(data)
const readonlyData = readonly(data)
const updateData = () => {
data.str = 'new str'
data.num++
data.arr.push('d')
}
const updateData = () => {
data.str = 'new str'
data.num++
data.arr.push('d')
}
// #ifdef APP
const updateReadonlyData = () => {
readonlyData.str = 'new readonly str'
readonlyData.num++
readonlyData.arr.push('e')
}
// #endif
</script>
\ No newline at end of file
const updateReadonlyData = () => {
readonlyData.str = 'new readonly str'
readonlyData.num++
readonlyData.arr.push('e')
}
</script>
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
新手
引导
客服
返回
顶部