Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
84fcdd8b
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
350
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看板
提交
84fcdd8b
编写于
5月 14, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: 优化示例及测试
上级
ee96f308
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
48 addition
and
45 deletion
+48
-45
pages/built-in/special-elements/template/template-composition.uvue
...lt-in/special-elements/template/template-composition.uvue
+4
-4
pages/built-in/special-elements/template/template-options.uvue
.../built-in/special-elements/template/template-options.uvue
+3
-3
pages/built-in/special-elements/template/template.test.js
pages/built-in/special-elements/template/template.test.js
+4
-5
pages/reactivity/advanced/shallow-reactive/shallow-reactive.test.js
...tivity/advanced/shallow-reactive/shallow-reactive.test.js
+2
-2
pages/reactivity/advanced/shallow-reactive/shallow-reactive.uvue
...eactivity/advanced/shallow-reactive/shallow-reactive.uvue
+9
-7
pages/reactivity/advanced/shallow-readonly/shallow-readonly.uvue
...eactivity/advanced/shallow-readonly/shallow-readonly.uvue
+5
-4
pages/reactivity/advanced/shallow-ref/shallow-ref.test.js
pages/reactivity/advanced/shallow-ref/shallow-ref.test.js
+2
-2
pages/reactivity/advanced/shallow-ref/shallow-ref.uvue
pages/reactivity/advanced/shallow-ref/shallow-ref.uvue
+7
-6
pages/reactivity/core/reactive/reactive.test.js
pages/reactivity/core/reactive/reactive.test.js
+1
-1
pages/reactivity/core/reactive/reactive.uvue
pages/reactivity/core/reactive/reactive.uvue
+1
-1
pages/reactivity/core/readonly/readonly.uvue
pages/reactivity/core/readonly/readonly.uvue
+5
-5
pages/reactivity/core/ref/ref.test.js
pages/reactivity/core/ref/ref.test.js
+1
-1
pages/reactivity/core/ref/ref.uvue
pages/reactivity/core/ref/ref.uvue
+4
-4
未找到文件。
pages/built-in/special-elements/template/template-composition.uvue
浏览文件 @
84fcdd8b
<template>
<view class="page">
<template v-if="dataInfo.isShow">
<
view class="title">{{ title }}</view
>
<
text id="title">{{ title }}</text
>
</template>
<
view class="show-botton" @click="handleShow">{{ dataInfo.isShow ? '点击隐藏' : '点击显示' }}</view
>
<
button id="show-botton" @click="handleShow">{{ dataInfo.isShow ? '点击隐藏' : '点击显示' }}</button
>
<template v-for="(item, index) in list" :key="index">
<view class="item">{{ index + 1 }}.{{ item.name }}</view>
</template>
...
...
@@ -31,14 +31,14 @@ const list = ref<ListItem[]>([
{
name: 'foo2'
}
]
as ListItem[]
)
])
const handleShow = () => {
dataInfo.isShow = !dataInfo.isShow
}
const goMapStyle = () => {
uni.navigateTo({ url: '/pages/built-in/
component
/template/template-map-style-composition' })
uni.navigateTo({ url: '/pages/built-in/
special-elements
/template/template-map-style-composition' })
}
defineExpose({
...
...
pages/built-in/special-elements/template/template-options.uvue
浏览文件 @
84fcdd8b
<template>
<view class="page">
<template v-if="dataInfo.isShow">
<
view class="title">{{ title }}</view
>
<
text id="title">{{ title }}</text
>
</template>
<
view class="show-botton" @click="handleShow">{{ dataInfo.isShow ? '点击隐藏' : '点击显示' }}</view
>
<
button id="show-botton" @click="handleShow">{{ dataInfo.isShow ? '点击隐藏' : '点击显示' }}</button
>
<template v-for="(item, index) in list" :key="index">
<view class="item">{{ index + 1 }}.{{ item.name }}</view>
</template>
...
...
@@ -39,7 +39,7 @@ export default {
this.dataInfo.isShow = !this.dataInfo.isShow
},
goMapStyle() {
uni.navigateTo({ url: '/pages/built-in/
component
/template/template-map-style-options' })
uni.navigateTo({ url: '/pages/built-in/
special-elements
/template/template-map-style-options' })
}
}
}
...
...
pages/built-in/special-elements/template/template.test.js
浏览文件 @
84fcdd8b
...
...
@@ -5,16 +5,15 @@ describe('built-in/special-elements/component', () => {
let
page
const
test
=
async
()
=>
{
await
page
.
waitFor
(
'
view
'
)
expect
.
assertions
(
4
);
const
showBtn
=
await
page
.
$
(
'
.show-botton
'
)
const
showBtn
=
await
page
.
$
(
'
#show-botton
'
)
expect
(
await
showBtn
.
text
()).
toBe
(
"
点击显示
"
)
await
showBtn
.
tap
()
const
dataInfo
=
await
page
.
data
(
'
dataInfo
'
)
expect
(
dataInfo
.
isShow
).
toBeTruthy
()
const
getTitle
=
await
page
.
$
(
'
.
title
'
)
const
getTitle
=
await
page
.
$
(
'
#
title
'
)
expect
(
await
getTitle
.
text
()).
toBe
(
"
hello
"
)
const
getShow
=
await
page
.
$
(
'
.show-botton
'
)
expect
(
await
getShow
.
text
()).
toBe
(
"
点击隐藏
"
)
expect
(
await
showBtn
.
text
()).
toBe
(
"
点击隐藏
"
)
expect
((
await
page
.
$$
(
'
.item
'
)).
length
).
toBe
(
2
)
}
it
(
'
template Options API
'
,
async
()
=>
{
...
...
pages/reactivity/advanced/shallow-reactive/shallow-reactive.test.js
浏览文件 @
84fcdd8b
...
...
@@ -15,12 +15,12 @@ describe('shallowReactive', () => {
const
stateNestedCount
=
await
page
.
$
(
'
#state-nested-count
'
)
expect
(
await
stateNestedCount
.
text
()).
toBe
(
'
0
'
)
const
incrementStateNestedCountBtn
=
await
page
.
$
(
'
.
increment-state-nested-count-btn
'
)
const
incrementStateNestedCountBtn
=
await
page
.
$
(
'
#
increment-state-nested-count-btn
'
)
await
incrementStateNestedCountBtn
.
tap
()
expect
(
await
stateNestedCount
.
text
()).
toBe
(
'
0
'
)
const
incrementStateCountBtn
=
await
page
.
$
(
'
.
increment-state-count-btn
'
)
const
incrementStateCountBtn
=
await
page
.
$
(
'
#
increment-state-count-btn
'
)
await
incrementStateCountBtn
.
tap
()
if
(
isWeb
)
{
...
...
pages/reactivity/advanced/shallow-reactive/shallow-reactive.uvue
浏览文件 @
84fcdd8b
...
...
@@ -9,12 +9,13 @@
<text id="state-nested-count">{{ state.nested.count }}</text>
</view>
<button
class="increment-state-count-btn mb-10"
id="increment-state-count-btn"
class="mb-10"
@click="incrementStateCount">
increment state.count
</button>
<button
class
="increment-state-nested-count-btn"
id
="increment-state-nested-count-btn"
@click="incrementStateNestedCount">
increment state.nested.count
</button>
...
...
@@ -29,12 +30,13 @@ type State = {
count : number,
nested : StateNested
}
const state = shallowReactive({
// 可通过泛型指定类型
const state = shallowReactive<State>({
count: 0,
nested: {
count: 0
}
as StateNested
}
as State
)
}
})
const incrementStateCount = () => {
state.count++
...
...
pages/reactivity/advanced/shallow-readonly/shallow-readonly.uvue
浏览文件 @
84fcdd8b
...
...
@@ -36,12 +36,13 @@ type State = {
count : number,
nested : StateNested
}
const state = shallowReadonly({
// 可通过泛型指定类型
const state = shallowReadonly<State>({
count: 0,
nested: {
count: 0
}
as StateNested
}
as State
)
}
})
// #ifdef APP
const incrementStateCount = () => {
...
...
pages/reactivity/advanced/shallow-ref/shallow-ref.test.js
浏览文件 @
84fcdd8b
...
...
@@ -10,12 +10,12 @@ describe('shallowRef', () => {
const
stateCount
=
await
page
.
$
(
'
#state-count
'
)
expect
(
await
stateCount
.
text
()).
toBe
(
'
0
'
)
const
incrementStateCountBtn
=
await
page
.
$
(
'
.
increment-state-count-btn
'
)
const
incrementStateCountBtn
=
await
page
.
$
(
'
#
increment-state-count-btn
'
)
await
incrementStateCountBtn
.
tap
()
expect
(
await
stateCount
.
text
()).
toBe
(
'
0
'
)
const
updateStateBtn
=
await
page
.
$
(
'
.
update-state-btn
'
)
const
updateStateBtn
=
await
page
.
$
(
'
#
update-state-btn
'
)
await
updateStateBtn
.
tap
()
expect
(
await
stateCount
.
text
()).
toBe
(
'
1
'
)
...
...
pages/reactivity/advanced/shallow-ref/shallow-ref.uvue
浏览文件 @
84fcdd8b
...
...
@@ -5,11 +5,12 @@
<text id="state-count">{{ state.count }}</text>
</view>
<button
class="increment-state-count-btn mb-10"
id="increment-state-count-btn"
class="mb-10"
@click="incrementStateCount">
increment state.count
</button>
<button
class
="update-state-btn" @click="updateState">update state</button>
<button
id
="update-state-btn" @click="updateState">update state</button>
</view>
</template>
...
...
@@ -17,10 +18,10 @@
type State = {
count: number
}
const state = shallowRef({
// 可通过泛型指定类型
const state = shallowRef
<State>
({
count: 0
}
as State
)
})
const incrementStateCount = () => {
state.value.count++
...
...
pages/reactivity/core/reactive/reactive.test.js
浏览文件 @
84fcdd8b
...
...
@@ -19,7 +19,7 @@ describe('reactive', () => {
const
objArr
=
await
page
.
$
(
'
#obj-arr
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
["a","b","c"]
'
)
const
updateBtn
=
await
page
.
$
(
'
.
update-btn
'
)
const
updateBtn
=
await
page
.
$
(
'
#
update-btn
'
)
await
updateBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
2
'
)
...
...
pages/reactivity/core/reactive/reactive.uvue
浏览文件 @
84fcdd8b
...
...
@@ -16,7 +16,7 @@
<text>obj.arr:</text>
<text id="obj-arr">{{ JSON.stringify(obj['arr']) }}</text>
</view>
<button
class
="update-btn" @click="update">update</button>
<button
id
="update-btn" @click="update">update</button>
</view>
</template>
...
...
pages/reactivity/core/readonly/readonly.uvue
浏览文件 @
84fcdd8b
...
...
@@ -40,14 +40,14 @@ type Data = {
num : number,
arr : string[]
}
const data = reactive({
// 可通过泛型指定类型
const data = reactive
<Data>
({
str: 'default str',
num: 0,
arr: ['a', 'b', 'c']
}
as Data
)
const readonlyData = readonly(data)
})
// 可通过泛型指定类型
const readonlyData = readonly
<Data>
(data)
const updateData = () => {
data.str = 'new str'
...
...
pages/reactivity/core/ref/ref.test.js
浏览文件 @
84fcdd8b
...
...
@@ -14,7 +14,7 @@ describe('ref', () => {
const
counterCount
=
await
page
.
$
(
'
#counter-count
'
)
expect
(
await
counterCount
.
text
()).
toBe
(
'
counter.count: 0
'
)
const
incrementBtn
=
await
page
.
$
(
'
.
increment-btn
'
)
const
incrementBtn
=
await
page
.
$
(
'
#
increment-btn
'
)
await
incrementBtn
.
tap
()
expect
(
await
count1
.
text
()).
toBe
(
'
count1: 2
'
)
...
...
pages/reactivity/core/ref/ref.uvue
浏览文件 @
84fcdd8b
...
...
@@ -3,7 +3,7 @@
<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
class
="increment-btn" @click="increment">increment</button>
<button
id
="increment-btn" @click="increment">increment</button>
</view>
</template>
...
...
@@ -15,10 +15,10 @@
type Counter = {
count : number
}
//
TODO: Android 端暂不支持通过泛型指定类型,可通过 as 方式
指定类型
const counter = ref({
//
可通过泛型
指定类型
const counter = ref
<Counter>
({
count: 0
}
as Counter
)
})
const increment = () => {
count1.value++
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录