Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
feb9f502
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
360
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看板
提交
feb9f502
编写于
7个月前
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(reactivity): 优化 ref 示例及测试
上级
9c09df24
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
31 deletion
+59
-31
pages/reactivity/core/ref/ref.test.js
pages/reactivity/core/ref/ref.test.js
+16
-10
pages/reactivity/core/ref/ref.uvue
pages/reactivity/core/ref/ref.uvue
+43
-21
未找到文件。
pages/reactivity/core/ref/ref.test.js
浏览文件 @
feb9f502
...
...
@@ -7,19 +7,25 @@ describe('ref', () => {
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
basic
'
,
async
()
=>
{
const
count1
=
await
page
.
$
(
'
#count1
'
)
expect
(
await
count1
.
text
()).
toBe
(
'
count1: 0
'
)
const
count2
=
await
page
.
$
(
'
#count2
'
)
expect
(
await
count2
.
text
()).
toBe
(
'
count2: 0
'
)
const
count
=
await
page
.
$
(
'
#count
'
)
expect
(
await
count
.
text
()).
toBe
(
'
0
'
)
const
str
=
await
page
.
$
(
'
#str
'
)
expect
(
await
str
.
text
()).
toBe
(
'
default str
'
)
const
bool
=
await
page
.
$
(
'
#bool
'
)
expect
(
await
bool
.
text
()).
toBe
(
'
false
'
)
const
arr
=
await
page
.
$
(
'
#arr
'
)
expect
(
await
arr
.
text
()).
toBe
(
'
[1,2,3]
'
)
const
counterCount
=
await
page
.
$
(
'
#counter-count
'
)
expect
(
await
counterCount
.
text
()).
toBe
(
'
counter.count:
0
'
)
expect
(
await
counterCount
.
text
()).
toBe
(
'
0
'
)
const
incrementBtn
=
await
page
.
$
(
'
#increment
-btn
'
)
await
increment
Btn
.
tap
()
const
changeDataBtn
=
await
page
.
$
(
'
#change-data
-btn
'
)
await
changeData
Btn
.
tap
()
expect
(
await
count1
.
text
()).
toBe
(
'
count1: 2
'
)
expect
(
await
count2
.
text
()).
toBe
(
'
count2: 2
'
)
expect
(
await
counterCount
.
text
()).
toBe
(
'
counter.count: 1
'
)
expect
(
await
count
.
text
()).
toBe
(
'
1
'
)
expect
(
await
str
.
text
()).
toBe
(
'
new str
'
)
expect
(
await
bool
.
text
()).
toBe
(
'
true
'
)
expect
(
await
arr
.
text
()).
toBe
(
'
[1,2,3,4]
'
)
expect
(
await
counterCount
.
text
()).
toBe
(
'
1
'
)
})
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pages/reactivity/core/ref/ref.uvue
浏览文件 @
feb9f502
<template>
<view class="page">
<text id="count1" class="mb-10">count1: {{ count1 }}</text>
<text id="count2" class="mb-10">count2: {{ count2 }}</text>
<text id="counter-count" class="mb-10">counter.count: {{ counter.count }}</text>
<button id="increment-btn" @click="increment">increment</button>
<view class="flex justify-between flex-row mb-10">
<text>count:</text>
<text id="count">{{ count }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>str:</text>
<text id="str">{{ str }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>bool:</text>
<text id="bool">{{ bool }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>arr:</text>
<text id="arr">{{ JSON.stringify(arr) }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>counter.count:</text>
<text id="counter-count">{{ counter.count }}</text>
</view>
<button id="change-data-btn" @click="changeData">change data</button>
</view>
</template>
<script setup lang='uts'>
// 基础数据类型可自动推导类型
const count1 = ref(0)
const count2 = ref(count1)
<script setup lang="uts">
// 基础数据类型可自动推导类型
const count = ref(0)
const str = ref('default str')
const bool = ref(false)
type Counter = {
count : number
}
// 可通过泛型指定类型
const counter = ref<Counter>({
count: 0
})
// 可通过泛型指定类型
const arr = ref<number[]>([1, 2, 3])
type Counter = {
count : number
}
// 可通过泛型指定类型
const counter = ref<Counter>({
count: 0
})
const increment = () => {
count1.value++
count2.value++
counter.value.count++
}
</script>
\ No newline at end of file
const changeData = () => {
count.value++
str.value = 'new str'
bool.value = !bool.value
arr.value.push(arr.value.length + 1)
counter.value.count++
}
</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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录