Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
54f5e32c
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
401
Star
3
Fork
10
代码
文件
提交
分支
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看板
提交
54f5e32c
编写于
4月 15, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: $data
上级
52dd8cd9
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
124 addition
and
75 deletion
+124
-75
pages.json
pages.json
+13
-6
pages/component-instance/data/data-composition.uvue
pages/component-instance/data/data-composition.uvue
+33
-0
pages/component-instance/data/data-options.uvue
pages/component-instance/data/data-options.uvue
+36
-0
pages/component-instance/data/data.test.js
pages/component-instance/data/data.test.js
+24
-17
pages/component-instance/data/data.uvue
pages/component-instance/data/data.uvue
+0
-49
pages/index/index.uvue
pages/index/index.uvue
+16
-1
refactor:options-API-composition-API-correspondence.md
refactor:options-API-composition-API-correspondence.md
+2
-2
未找到文件。
pages.json
浏览文件 @
54f5e32c
...
...
@@ -48,6 +48,19 @@
"navigationBarTitleText"
:
"useAttrs"
}
},
{
"path"
:
"pages/component-instance/data/data-options"
,
"style"
:
{
"navigationBarTitleText"
:
"$data"
}
},
{
"path"
:
"pages/component-instance/data/data-composition"
,
"style"
:
{
"navigationBarTitleText"
:
"data 组合式 API"
}
},
{
"path"
:
"pages/built-in-component/keep-alive/keep-alive"
,
"style"
:
{
...
...
@@ -209,12 +222,6 @@
"navigationBarTitleText"
:
"component-lifecycle"
}
},
{
"path"
:
"pages/component-instance/data/data"
,
"style"
:
{
"navigationBarTitleText"
:
"$data"
}
},
{
"path"
:
"pages/component-instance/props/props"
,
"style"
:
{
...
...
pages/component-instance/data/data-composition.uvue
0 → 100644
浏览文件 @
54f5e32c
<template>
<view class="page">
<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>num: </text>
<text id="num">{{ num }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>arr: </text>
<text id="arr">{{ arr.join(',') }}</text>
</view>
<button type="primary" @click="updateData">update data</button>
</view>
</template>
<script setup lang="uts">
const str = ref('default str')
const num = ref(0)
const arr = ref([1, 2, 3])
const updateData = () => {
str.value = 'new str'
num.value = 1
arr.value = [4, 5, 6]
}
defineExpose({
updateData
})
</script>
pages/component-instance/data/data-options.uvue
0 → 100644
浏览文件 @
54f5e32c
<template>
<view class="page">
<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>num: </text>
<text id="num">{{ num }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>arr: </text>
<text id="arr">{{ arr.join(',') }}</text>
</view>
<button type="primary" @click="updateData">update data</button>
</view>
</template>
<script lang="uts">
export default {
data() {
return {
str: 'default str',
num: 0,
arr: [1, 2, 3],
}
},
methods: {
updateData() {
this.str = 'new str'
this.num = 1
this.arr = [4, 5, 6]
},
},
}
</script>
pages/component-instance/data/data.test.js
浏览文件 @
54f5e32c
const
PAGE_PATH
=
'
/pages/component-instance/data/data
'
const
OPTIONS_PAGE_PATH
=
'
/pages/component-instance/data/data-options
'
const
COMPOSITION_PAGE_PATH
=
'
/pages/component-instance/data/data-composition
'
describe
(
'
$data
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
500
)
})
it
(
'
should data.val === 2
'
,
async
()
=>
{
const
plusButton
=
await
page
.
$
(
'
.plus
'
)
await
plusButton
.
tap
()
const
test
=
async
(
page
)
=>
{
const
str
=
await
page
.
$
(
'
#str
'
)
expect
(
await
str
.
text
()).
toBe
(
'
default str
'
)
const
num
=
await
page
.
$
(
'
#num
'
)
expect
(
await
num
.
text
()).
toBe
(
'
0
'
)
const
arr
=
await
page
.
$
(
'
#arr
'
)
expect
(
await
arr
.
text
()).
toBe
(
'
1,2,3
'
)
await
page
.
callMethod
(
'
updateData
'
)
expect
(
await
str
.
text
()).
toBe
(
'
new str
'
)
expect
(
await
num
.
text
()).
toBe
(
'
1
'
)
expect
(
await
arr
.
text
()).
toBe
(
'
4,5,6
'
)
}
const
val
=
await
page
.
$
(
'
.val
'
)
expect
(
await
val
.
text
()).
toBe
(
'
2
'
)
it
(
'
$data 选项式 API
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
OPTIONS_PAGE_PATH
)
await
test
(
page
)
});
it
(
'
should data.val === 1
'
,
async
()
=>
{
const
minusButton
=
await
page
.
$
(
'
.minus
'
)
await
minusButton
.
tap
()
const
val
=
await
page
.
$
(
'
.val
'
)
expect
(
await
val
.
text
()).
toBe
(
'
1
'
)
it
(
'
data 组合式 API
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
COMPOSITION_PAGE_PATH
)
await
test
(
page
)
})
})
pages/component-instance/data/data.uvue
已删除
100644 → 0
浏览文件 @
52dd8cd9
<template>
<view class="page">
<view class="row">初始值1: <text>1</text></view>
<view class="row">data.val: <text class="val">{{val}}</text></view>
<view class="row">data._val: <text class="_val">{{_val}}</text></view>
<view class="row">data.$val: <text class="$val">{{$val}}</text></view>
<view class="buttons">
<button class="btn plus" @click="click(1)">增加</button>
<button class="btn minus" @click="click(-1)">减少</button>
</view>
</view>
</template>
<script>
export default {
data () {
return {
val: 1,
_val: 1,
$val: 1
}
},
methods: {
click (num: number) {
this.val += num
this._val += num
this.$val += num
}
}
}
</script>
<style>
.row {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-bottom: 10px;
}
.buttons {
display: flex;
flex-direction: row;
margin-top: 10px;
}
.btn {
flex: 1;
margin: 0 5px;
}
</style>
pages/index/index.uvue
浏览文件 @
54f5e32c
...
...
@@ -123,7 +123,7 @@ export default {
children: [
{
id: 'attrs-options',
name: 'attrs
选项式 API',
name: 'attrs 选项式 API',
url: 'attrs-options',
},
{
...
...
@@ -132,6 +132,21 @@ export default {
url: 'attrs-composition',
}
]
},{
id: 'data',
name: 'data',
children: [
{
id: 'data-options',
name: 'data 选项式 API',
url: 'data-options',
},
{
id: 'data-composition',
name: 'data 组合式 API',
url: 'data-composition',
}
]
},
] as Page[],
}
...
...
refactor:options-API-composition-API-correspondence.md
浏览文件 @
54f5e32c
...
...
@@ -21,8 +21,8 @@ script 中不要有空的 data, onLoad, methods\
-
[x] app.use app.use
## component instance
-
[
] attrs useAttrs
-
[
] data
-
[
x
] attrs useAttrs
-
[
x
] data
-
[ ] props defineProps
-
[ ] el
-
[ ] options defineOptions
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录