Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
ed49b744
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看板
提交
ed49b744
编写于
12月 19, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: KeepAlive
上级
369acbc0
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
277 addition
and
12 deletion
+277
-12
common/uni.css
common/uni.css
+3
-0
components/keep-alive/Counter.uvue
components/keep-alive/Counter.uvue
+32
-0
components/keep-alive/Message.uvue
components/keep-alive/Message.uvue
+32
-0
components/keep-alive/ShouldExclude.uvue
components/keep-alive/ShouldExclude.uvue
+33
-0
pages.json
pages.json
+6
-0
pages/built-in-component/keep-alive/keep-alive.test.js
pages/built-in-component/keep-alive/keep-alive.test.js
+79
-0
pages/built-in-component/keep-alive/keep-alive.uvue
pages/built-in-component/keep-alive/keep-alive.uvue
+68
-0
pages/index.uvue
pages/index.uvue
+24
-12
未找到文件。
common/uni.css
浏览文件 @
ed49b744
.uni-common-mt
{
margin-top
:
30
rpx
;
}
.uni-common-mb
{
margin-bottom
:
30
rpx
;
}
.bold
{
font-weight
:
bold
;
}
components/keep-alive/Counter.uvue
0 → 100644
浏览文件 @
ed49b744
<template>
<view>
<text class="counter-text">count: {{ count }}</text>
<text class="uni-common-mt counter-btn" @click="increment"></text>
</view>
</template>
<script lang="uts">
export default {
name: 'Counter',
data() {
return {
count: 0
}
},
methods: {
increment() {
this.count++
}
}
}
</script>
<style>
.counter-btn {
height: 40px;
line-height: 40px;
border: 1px solid #ccc;
border-radius: 4px;
text-align: center;
}
</style>
components/keep-alive/Message.uvue
0 → 100644
浏览文件 @
ed49b744
<template>
<view>
<text class="uni-common-mt message-text">msg: {{msg}}</text>
<text class="uni-common-mt change-message" @click="changeMessage">change message</text>
</view>
</template>
<script lang="uts">
export default {
name: 'Message',
data() {
return {
msg: 'default message'
}
},
methods: {
changeMessage() {
this.msg = 'message changed'
}
}
}
</script>
<style>
.change-message {
height: 40px;
line-height: 40px;
border: 1px solid #ccc;
border-radius: 4px;
text-align: center;
}
</style>
components/keep-alive/ShouldExclude.uvue
0 → 100644
浏览文件 @
ed49b744
<template>
<view>
<text>should not be keep-alive</text>
<text class="uni-common-mt should-exclude-text">count: {{ count }}</text>
<text class="uni-common-mt should-exclude-btn" @click="increment">+</text>
</view>
</template>
<script lang="uts">
export default {
name: 'ShouldExclude',
data() {
return {
count: 0
}
},
methods: {
increment() {
this.count++
}
}
}
</script>
<style>
.should-exclude-btn{
height: 40px;
line-height: 40px;
border: 1px solid #ccc;
border-radius: 4px;
text-align: center;
}
</style>
pages.json
浏览文件 @
ed49b744
...
...
@@ -12,6 +12,12 @@
"navigationBarTitleText"
:
"app instance"
}
},
{
"path"
:
"pages/built-in-component/keep-alive/keep-alive"
,
"style"
:
{
"navigationBarTitleText"
:
"keep-alive"
}
},
{
"path"
:
"pages/directive/v-bind/v-bind"
,
"style"
:
{
...
...
pages/built-in-component/keep-alive/keep-alive.test.js
0 → 100644
浏览文件 @
ed49b744
const
PAGE_PATH
=
'
/pages/built-in-component/keep-alive/keep-alive
'
describe
(
'
keep-alive
'
,
()
=>
{
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
keep-alive
'
,
async
()
=>
{
const
shouldExcludeBtns
=
await
page
.
$$
(
'
.should-exclude-btn
'
)
for
(
let
i
=
0
;
i
<
shouldExcludeBtns
.
length
;
i
++
)
{
await
shouldExcludeBtns
[
i
].
tap
()
}
let
shouldExcludeTexts
=
await
page
.
$$
(
'
.should-exclude-text
'
)
for
(
let
i
=
0
;
i
<
shouldExcludeTexts
.
length
;
i
++
)
{
expect
(
await
shouldExcludeTexts
[
i
].
text
()).
toBe
(
'
count: 1
'
)
}
const
showCounterBtn
=
await
page
.
$
(
'
.show-counter
'
)
await
showCounterBtn
.
tap
()
const
counterBtns
=
await
page
.
$$
(
'
.counter-btn
'
)
for
(
let
i
=
0
;
i
<
counterBtns
.
length
;
i
++
)
{
await
counterBtns
[
i
].
tap
()
}
const
showShouldExcludeBtn
=
await
page
.
$
(
'
.show-should-exclude
'
)
await
showShouldExcludeBtn
.
tap
()
shouldExcludeTexts
=
await
page
.
$$
(
'
.should-exclude-text
'
)
for
(
let
i
=
0
;
i
<
shouldExcludeTexts
.
length
;
i
++
)
{
if
(
i
<
shouldExcludeBtns
.
length
-
1
)
{
expect
(
await
shouldExcludeTexts
[
i
].
text
()).
toBe
(
'
count: 0
'
)
}
else
{
expect
(
await
shouldExcludeTexts
[
i
].
text
()).
toBe
(
'
count: 1
'
)
}
}
await
showCounterBtn
.
tap
()
let
counterTexts
=
await
page
.
$$
(
'
.counter-text
'
)
for
(
let
i
=
0
;
i
<
counterTexts
.
length
;
i
++
)
{
expect
(
await
counterTexts
[
i
].
text
()).
toBe
(
'
count: 1
'
)
}
const
showMessageBtn
=
await
page
.
$
(
'
.show-message
'
)
await
showMessageBtn
.
tap
()
const
chnageMessageBtns
=
await
page
.
$$
(
'
.change-message
'
)
for
(
let
i
=
0
;
i
<
chnageMessageBtns
.
length
;
i
++
)
{
await
chnageMessageBtns
[
i
].
tap
()
}
let
messageTexts
=
await
page
.
$$
(
'
.message-text
'
)
for
(
let
i
=
0
;
i
<
messageTexts
.
length
;
i
++
)
{
expect
(
await
messageTexts
[
i
].
text
()).
toBe
(
'
msg: message changed
'
)
}
await
showCounterBtn
.
tap
()
counterTexts
=
await
page
.
$$
(
'
.counter-text
'
)
for
(
let
i
=
0
;
i
<
counterTexts
.
length
;
i
++
)
{
expect
(
await
counterTexts
[
i
].
text
()).
toBe
(
'
count: 1
'
)
}
await
showMessageBtn
.
tap
()
messageTexts
=
await
page
.
$$
(
'
.message-text
'
)
for
(
let
i
=
0
;
i
<
messageTexts
.
length
;
i
++
)
{
expect
(
await
messageTexts
[
i
].
text
()).
toBe
(
'
msg: message changed
'
)
}
await
showShouldExcludeBtn
.
tap
()
shouldExcludeTexts
=
await
page
.
$$
(
'
.should-exclude-text
'
)
for
(
let
i
=
0
;
i
<
shouldExcludeTexts
.
length
;
i
++
)
{
expect
(
await
shouldExcludeTexts
[
i
].
text
()).
toBe
(
'
count: 0
'
)
}
})
})
pages/built-in-component/keep-alive/keep-alive.uvue
0 → 100644
浏览文件 @
ed49b744
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view class="page">
<text class="bold uni-common-mb">include "Counter,Message"</text>
<KeepAlive include="Counter,Message">
<component :is='currentComponent'></component>
</KeepAlive>
<view class="hr"></view>
<text class="bold uni-common-mt uni-common-mb">include "/Counter|Message/"</text>
<KeepAlive :include="/Counter|Message/">
<component :is='currentComponent'></component>
</KeepAlive>
<view class="hr"></view>
<text class="bold uni-common-mt uni-common-mb">include "['Counter', 'Message']"</text>
<KeepAlive :include="['Counter', 'Message']">
<component :is='currentComponent'></component>
</KeepAlive>
<view class="hr"></view>
<text class="bold uni-common-mt uni-common-mb">exclude "ShouldExclude"</text>
<KeepAlive exclude="ShouldExclude">
<component :is='currentComponent'></component>
</KeepAlive>
<view class="hr"></view>
<text class="bold uni-common-mt uni-common-mb">max 2</text>
<KeepAlive :max="2">
<component :is='currentComponent'></component>
</KeepAlive>
<view class="hr"></view>
<button class="uni-common-mt show-counter" @click="changeComponent('Counter')">show Counter</button>
<button class="uni-common-mt show-message" @click="changeComponent('Message')">show Message</button>
<button class="uni-common-mt show-should-exclude" @click="changeComponent('ShouldExclude')">show ShouldExclude</button>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script lang="uts">
import Counter from '@/components/keep-alive/Counter.uvue'
import Message from '@/components/keep-alive/Message.uvue'
import ShouldExclude from '@/components/keep-alive/ShouldExclude.uvue'
export default {
components: {
Counter,
Message,
ShouldExclude
},
data() {
return {
currentComponent: 'ShouldExclude'
}
},
methods: {
changeComponent(componentName : string) {
this.currentComponent = componentName
}
}
}
</script>
<style>
.hr {
margin-top: 30rpx;
border-bottom: 1px solid #ccc;
}
</style>
pages/index.uvue
浏览文件 @
ed49b744
...
...
@@ -51,18 +51,30 @@
data() {
return {
list: [
{
id: 'app-instance',
name: 'App 实例',
open: false,
pages: [
{
name: 'index',
url: 'index',
enable: true,
},
] as PageItem[],
},
{
id: 'app-instance',
name: 'App 实例',
open: false,
pages: [
{
name: 'index',
url: 'index',
enable: true,
},
] as PageItem[],
},
{
id: 'built-in-component',
name: '内置组件',
open: false,
pages: [
{
name: 'keepAlive',
url: 'keep-alive',
enable: true,
},
] as PageItem[],
},
{
id: 'lifecycle',
name: '生命周期',
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录