Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
84fcdd8b
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看板
提交
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>
<template>
<view class="page">
<view class="page">
<template v-if="dataInfo.isShow">
<template v-if="dataInfo.isShow">
<
view class="title">{{ title }}</view
>
<
text id="title">{{ title }}</text
>
</template>
</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">
<template v-for="(item, index) in list" :key="index">
<view class="item">{{ index + 1 }}.{{ item.name }}</view>
<view class="item">{{ index + 1 }}.{{ item.name }}</view>
</template>
</template>
...
@@ -31,14 +31,14 @@ const list = ref<ListItem[]>([
...
@@ -31,14 +31,14 @@ const list = ref<ListItem[]>([
{
{
name: 'foo2'
name: 'foo2'
}
}
]
as ListItem[]
)
])
const handleShow = () => {
const handleShow = () => {
dataInfo.isShow = !dataInfo.isShow
dataInfo.isShow = !dataInfo.isShow
}
}
const goMapStyle = () => {
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({
defineExpose({
...
...
pages/built-in/special-elements/template/template-options.uvue
浏览文件 @
84fcdd8b
<template>
<template>
<view class="page">
<view class="page">
<template v-if="dataInfo.isShow">
<template v-if="dataInfo.isShow">
<
view class="title">{{ title }}</view
>
<
text id="title">{{ title }}</text
>
</template>
</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">
<template v-for="(item, index) in list" :key="index">
<view class="item">{{ index + 1 }}.{{ item.name }}</view>
<view class="item">{{ index + 1 }}.{{ item.name }}</view>
</template>
</template>
...
@@ -39,7 +39,7 @@ export default {
...
@@ -39,7 +39,7 @@ export default {
this.dataInfo.isShow = !this.dataInfo.isShow
this.dataInfo.isShow = !this.dataInfo.isShow
},
},
goMapStyle() {
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', () => {
...
@@ -5,16 +5,15 @@ describe('built-in/special-elements/component', () => {
let
page
let
page
const
test
=
async
()
=>
{
const
test
=
async
()
=>
{
await
page
.
waitFor
(
'
view
'
)
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
()
await
showBtn
.
tap
()
const
dataInfo
=
await
page
.
data
(
'
dataInfo
'
)
const
dataInfo
=
await
page
.
data
(
'
dataInfo
'
)
expect
(
dataInfo
.
isShow
).
toBeTruthy
()
expect
(
dataInfo
.
isShow
).
toBeTruthy
()
const
getTitle
=
await
page
.
$
(
'
.
title
'
)
const
getTitle
=
await
page
.
$
(
'
#
title
'
)
expect
(
await
getTitle
.
text
()).
toBe
(
"
hello
"
)
expect
(
await
getTitle
.
text
()).
toBe
(
"
hello
"
)
const
getShow
=
await
page
.
$
(
'
.show-botton
'
)
expect
(
await
showBtn
.
text
()).
toBe
(
"
点击隐藏
"
)
expect
(
await
getShow
.
text
()).
toBe
(
"
点击隐藏
"
)
expect
((
await
page
.
$$
(
'
.item
'
)).
length
).
toBe
(
2
)
expect
((
await
page
.
$$
(
'
.item
'
)).
length
).
toBe
(
2
)
}
}
it
(
'
template Options API
'
,
async
()
=>
{
it
(
'
template Options API
'
,
async
()
=>
{
...
...
pages/reactivity/advanced/shallow-reactive/shallow-reactive.test.js
浏览文件 @
84fcdd8b
...
@@ -15,12 +15,12 @@ describe('shallowReactive', () => {
...
@@ -15,12 +15,12 @@ describe('shallowReactive', () => {
const
stateNestedCount
=
await
page
.
$
(
'
#state-nested-count
'
)
const
stateNestedCount
=
await
page
.
$
(
'
#state-nested-count
'
)
expect
(
await
stateNestedCount
.
text
()).
toBe
(
'
0
'
)
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
()
await
incrementStateNestedCountBtn
.
tap
()
expect
(
await
stateNestedCount
.
text
()).
toBe
(
'
0
'
)
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
()
await
incrementStateCountBtn
.
tap
()
if
(
isWeb
)
{
if
(
isWeb
)
{
...
...
pages/reactivity/advanced/shallow-reactive/shallow-reactive.uvue
浏览文件 @
84fcdd8b
...
@@ -8,13 +8,14 @@
...
@@ -8,13 +8,14 @@
<text>state.nested.count:</text>
<text>state.nested.count:</text>
<text id="state-nested-count">{{ state.nested.count }}</text>
<text id="state-nested-count">{{ state.nested.count }}</text>
</view>
</view>
<button
<button
class="increment-state-count-btn mb-10"
id="increment-state-count-btn"
class="mb-10"
@click="incrementStateCount">
@click="incrementStateCount">
increment state.count
increment state.count
</button>
</button>
<button
<button
class
="increment-state-nested-count-btn"
id
="increment-state-nested-count-btn"
@click="incrementStateNestedCount">
@click="incrementStateNestedCount">
increment state.nested.count
increment state.nested.count
</button>
</button>
...
@@ -28,13 +29,14 @@ type StateNested = {
...
@@ -28,13 +29,14 @@ type StateNested = {
type State = {
type State = {
count : number,
count : number,
nested : StateNested
nested : StateNested
}
}
const state = shallowReactive({
// 可通过泛型指定类型
const state = shallowReactive<State>({
count: 0,
count: 0,
nested: {
nested: {
count: 0
count: 0
}
as StateNested
}
}
as State
)
})
const incrementStateCount = () => {
const incrementStateCount = () => {
state.count++
state.count++
...
...
pages/reactivity/advanced/shallow-readonly/shallow-readonly.uvue
浏览文件 @
84fcdd8b
...
@@ -35,13 +35,14 @@ type StateNested = {
...
@@ -35,13 +35,14 @@ type StateNested = {
type State = {
type State = {
count : number,
count : number,
nested : StateNested
nested : StateNested
}
}
const state = shallowReadonly({
// 可通过泛型指定类型
const state = shallowReadonly<State>({
count: 0,
count: 0,
nested: {
nested: {
count: 0
count: 0
}
as StateNested
}
}
as State
)
})
// #ifdef APP
// #ifdef APP
const incrementStateCount = () => {
const incrementStateCount = () => {
...
...
pages/reactivity/advanced/shallow-ref/shallow-ref.test.js
浏览文件 @
84fcdd8b
...
@@ -10,12 +10,12 @@ describe('shallowRef', () => {
...
@@ -10,12 +10,12 @@ describe('shallowRef', () => {
const
stateCount
=
await
page
.
$
(
'
#state-count
'
)
const
stateCount
=
await
page
.
$
(
'
#state-count
'
)
expect
(
await
stateCount
.
text
()).
toBe
(
'
0
'
)
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
()
await
incrementStateCountBtn
.
tap
()
expect
(
await
stateCount
.
text
()).
toBe
(
'
0
'
)
expect
(
await
stateCount
.
text
()).
toBe
(
'
0
'
)
const
updateStateBtn
=
await
page
.
$
(
'
.
update-state-btn
'
)
const
updateStateBtn
=
await
page
.
$
(
'
#
update-state-btn
'
)
await
updateStateBtn
.
tap
()
await
updateStateBtn
.
tap
()
expect
(
await
stateCount
.
text
()).
toBe
(
'
1
'
)
expect
(
await
stateCount
.
text
()).
toBe
(
'
1
'
)
...
...
pages/reactivity/advanced/shallow-ref/shallow-ref.uvue
浏览文件 @
84fcdd8b
...
@@ -4,12 +4,13 @@
...
@@ -4,12 +4,13 @@
<text>state.count:</text>
<text>state.count:</text>
<text id="state-count">{{ state.count }}</text>
<text id="state-count">{{ state.count }}</text>
</view>
</view>
<button
<button
class="increment-state-count-btn mb-10"
id="increment-state-count-btn"
class="mb-10"
@click="incrementStateCount">
@click="incrementStateCount">
increment state.count
increment state.count
</button>
</button>
<button
class
="update-state-btn" @click="updateState">update state</button>
<button
id
="update-state-btn" @click="updateState">update state</button>
</view>
</view>
</template>
</template>
...
@@ -17,10 +18,10 @@
...
@@ -17,10 +18,10 @@
type State = {
type State = {
count: number
count: number
}
}
// 可通过泛型指定类型
const state = shallowRef({
const state = shallowRef
<State>
({
count: 0
count: 0
}
as State
)
})
const incrementStateCount = () => {
const incrementStateCount = () => {
state.value.count++
state.value.count++
...
...
pages/reactivity/core/reactive/reactive.test.js
浏览文件 @
84fcdd8b
...
@@ -19,7 +19,7 @@ describe('reactive', () => {
...
@@ -19,7 +19,7 @@ describe('reactive', () => {
const
objArr
=
await
page
.
$
(
'
#obj-arr
'
)
const
objArr
=
await
page
.
$
(
'
#obj-arr
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
["a","b","c"]
'
)
expect
(
await
objArr
.
text
()).
toBe
(
'
["a","b","c"]
'
)
const
updateBtn
=
await
page
.
$
(
'
.
update-btn
'
)
const
updateBtn
=
await
page
.
$
(
'
#
update-btn
'
)
await
updateBtn
.
tap
()
await
updateBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
'
2
'
)
expect
(
await
count
.
text
()).
toBe
(
'
2
'
)
...
...
pages/reactivity/core/reactive/reactive.uvue
浏览文件 @
84fcdd8b
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
<text>obj.arr:</text>
<text>obj.arr:</text>
<text id="obj-arr">{{ JSON.stringify(obj['arr']) }}</text>
<text id="obj-arr">{{ JSON.stringify(obj['arr']) }}</text>
</view>
</view>
<button
class
="update-btn" @click="update">update</button>
<button
id
="update-btn" @click="update">update</button>
</view>
</view>
</template>
</template>
...
...
pages/reactivity/core/readonly/readonly.uvue
浏览文件 @
84fcdd8b
...
@@ -40,14 +40,14 @@ type Data = {
...
@@ -40,14 +40,14 @@ type Data = {
num : number,
num : number,
arr : string[]
arr : string[]
}
}
// 可通过泛型指定类型
const data = reactive({
const data = reactive
<Data>
({
str: 'default str',
str: 'default str',
num: 0,
num: 0,
arr: ['a', 'b', 'c']
arr: ['a', 'b', 'c']
}
as Data
)
})
// 可通过泛型指定类型
const readonlyData = readonly(data)
const readonlyData = readonly
<Data>
(data)
const updateData = () => {
const updateData = () => {
data.str = 'new str'
data.str = 'new str'
...
...
pages/reactivity/core/ref/ref.test.js
浏览文件 @
84fcdd8b
...
@@ -14,7 +14,7 @@ describe('ref', () => {
...
@@ -14,7 +14,7 @@ describe('ref', () => {
const
counterCount
=
await
page
.
$
(
'
#counter-count
'
)
const
counterCount
=
await
page
.
$
(
'
#counter-count
'
)
expect
(
await
counterCount
.
text
()).
toBe
(
'
counter.count: 0
'
)
expect
(
await
counterCount
.
text
()).
toBe
(
'
counter.count: 0
'
)
const
incrementBtn
=
await
page
.
$
(
'
.
increment-btn
'
)
const
incrementBtn
=
await
page
.
$
(
'
#
increment-btn
'
)
await
incrementBtn
.
tap
()
await
incrementBtn
.
tap
()
expect
(
await
count1
.
text
()).
toBe
(
'
count1: 2
'
)
expect
(
await
count1
.
text
()).
toBe
(
'
count1: 2
'
)
...
...
pages/reactivity/core/ref/ref.uvue
浏览文件 @
84fcdd8b
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
<text id="count1" class="mb-10">count1: {{ count1 }}</text>
<text id="count1" class="mb-10">count1: {{ count1 }}</text>
<text id="count2" class="mb-10">count2: {{ count2 }}</text>
<text id="count2" class="mb-10">count2: {{ count2 }}</text>
<text id="counter-count" class="mb-10">counter.count: {{ counter.count }}</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>
</view>
</template>
</template>
...
@@ -15,10 +15,10 @@
...
@@ -15,10 +15,10 @@
type Counter = {
type Counter = {
count : number
count : number
}
}
//
TODO: Android 端暂不支持通过泛型指定类型,可通过 as 方式
指定类型
//
可通过泛型
指定类型
const counter = ref({
const counter = ref
<Counter>
({
count: 0
count: 0
}
as Counter
)
})
const increment = () => {
const increment = () => {
count1.value++
count1.value++
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录