Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
f4f42962
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5929
Star
89
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
17
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
17
Issue
17
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f4f42962
编写于
11月 21, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 补充 globalData 示例及测试
上级
52e52d95
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
77 addition
and
45 deletion
+77
-45
App.uvue
App.uvue
+6
-1
pages/API/get-app/get-app.test.js
pages/API/get-app/get-app.test.js
+17
-7
pages/API/get-app/get-app.uvue
pages/API/get-app/get-app.uvue
+54
-37
未找到文件。
App.uvue
浏览文件 @
f4f42962
...
...
@@ -2,7 +2,12 @@
import { state, setLifeCycleNum } from '@/store/index.uts'
let firstBackTime = 0
export default {
export default {
globalData: {
str: 'global data str',
num: 123,
bool: true,
},
onLaunch: function () {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1000)
...
...
pages/API/get-app/get-app.test.js
浏览文件 @
f4f42962
const
PAGE_PATH
=
'
/pages/API/get-app/get-app
'
describe
(
'
getApp
'
,
()
=>
{
it
(
'
getApp
'
,
async
()
=>
{
const
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
1000
)
const
oldData
=
await
page
.
data
()
let
page
=
null
beforeAll
(
async
()
=>
{
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
'
view
'
)
})
it
(
'
globalData
'
,
async
()
=>
{
await
page
.
callMethod
(
'
getGlobalData
'
)
const
data
=
await
page
.
data
()
expect
(
data
.
globalDataStr
).
toBe
(
'
global data str
'
)
expect
(
data
.
globalDataNum
).
toBe
(
123
)
expect
(
data
.
globalDataBool
).
toBe
(
true
)
})
it
(
'
method
'
,
async
()
=>
{
const
oldLifeCycleNum
=
await
page
.
data
(
'
lifeCycleNum
'
)
await
page
.
callMethod
(
'
_increasetLifeCycleNum
'
)
const
new
Data
=
await
page
.
data
(
)
expect
(
new
Data
.
lifeCycleNum
-
oldData
.
l
ifeCycleNum
).
toBe
(
100
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
old
Data
.
l
ifeCycleNum
)
const
new
LifeCycleNum
=
await
page
.
data
(
'
lifeCycleNum
'
)
expect
(
new
LifeCycleNum
-
oldL
ifeCycleNum
).
toBe
(
100
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
old
L
ifeCycleNum
)
})
})
pages/API/get-app/get-app.uvue
浏览文件 @
f4f42962
<template>
<view>
<page-head title="getApp"></page-head>
<view class="uni-padding-wrap">
<text>点击按钮调用 App.uvue methods</text>
<text class="margin-top:6px;">increasetLifeCycleNum 方法</text>
<button class="uni-common-mt" @click="_increasetLifeCycleNum">
increase lifeCycleNum
<template>
<view>
<page-head title="getApp"></page-head>
<view class="uni-padding-wrap">
<button @click="getGlobalData">
get globalData
</button>
<text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
</view>
</view>
</template>
<script lang="uts">
import { State, state, setLifeCycleNum } from '@/store/index.uts'
export default {
data() {
return {
lifeCycleNum: 0,
}
},
onReady() {
this.lifeCycleNum = state.lifeCycleNum
},
methods: {
_increasetLifeCycleNum: function () {
const app = getApp()
app.increasetLifeCycleNum()
this.lifeCycleNum = state.lifeCycleNum
},
// 自动化测试
setLifeCycleNum(num: number) {
setLifeCycleNum(num)
},
},
}
<template v-if="globalDataStr">
<text class="uni-common-mt">globalData str: {{ globalDataStr }}</text>
<text class="uni-common-mt">globalData num: {{ globalDataNum }}</text>
<text class="uni-common-mt">globalData boolean: {{ globalDataBool }}</text>
</template>
<text class="uni-common-mt">点击按钮调用 App.uvue methods</text>
<text class="margin-top:6px;">increasetLifeCycleNum 方法</text>
<button class="uni-common-mt" @click="_increasetLifeCycleNum">
increase lifeCycleNum
</button>
<text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
</view>
</view>
</template>
<script lang="uts">
import { state, setLifeCycleNum } from '@/store/index.uts'
export default {
data() {
return {
globalDataStr: '',
globalDataNum: 0,
globalDataBool: false,
lifeCycleNum: 0,
}
},
onReady() {
this.lifeCycleNum = state.lifeCycleNum
},
methods: {
getGlobalData() {
const app = getApp()
this.globalDataStr = app.globalData.str
this.globalDataNum = app.globalData.num
this.globalDataBool = app.globalData.bool
},
_increasetLifeCycleNum: function () {
const app = getApp()
app.increasetLifeCycleNum()
this.lifeCycleNum = state.lifeCycleNum
},
// 自动化测试
setLifeCycleNum(num : number) {
setLifeCycleNum(num)
}
},
}
</script>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录