Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
f4f42962
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5992
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
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 @@
...
@@ -2,7 +2,12 @@
import { state, setLifeCycleNum } from '@/store/index.uts'
import { state, setLifeCycleNum } from '@/store/index.uts'
let firstBackTime = 0
let firstBackTime = 0
export default {
export default {
globalData: {
str: 'global data str',
num: 123,
bool: true,
},
onLaunch: function () {
onLaunch: function () {
// 自动化测试
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1000)
setLifeCycleNum(state.lifeCycleNum + 1000)
...
...
pages/API/get-app/get-app.test.js
浏览文件 @
f4f42962
const
PAGE_PATH
=
'
/pages/API/get-app/get-app
'
const
PAGE_PATH
=
'
/pages/API/get-app/get-app
'
describe
(
'
getApp
'
,
()
=>
{
describe
(
'
getApp
'
,
()
=>
{
it
(
'
getApp
'
,
async
()
=>
{
let
page
=
null
const
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
beforeAll
(
async
()
=>
{
await
page
.
waitFor
(
1000
)
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
const
oldData
=
await
page
.
data
()
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
'
)
await
page
.
callMethod
(
'
_increasetLifeCycleNum
'
)
const
new
Data
=
await
page
.
data
(
)
const
new
LifeCycleNum
=
await
page
.
data
(
'
lifeCycleNum
'
)
expect
(
new
Data
.
lifeCycleNum
-
oldData
.
l
ifeCycleNum
).
toBe
(
100
)
expect
(
new
LifeCycleNum
-
oldL
ifeCycleNum
).
toBe
(
100
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
old
Data
.
l
ifeCycleNum
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
old
L
ifeCycleNum
)
})
})
})
})
pages/API/get-app/get-app.uvue
浏览文件 @
f4f42962
<template>
<template>
<view>
<view>
<page-head title="getApp"></page-head>
<page-head title="getApp"></page-head>
<view class="uni-padding-wrap">
<view class="uni-padding-wrap">
<text>点击按钮调用 App.uvue methods</text>
<button @click="getGlobalData">
<text class="margin-top:6px;">increasetLifeCycleNum 方法</text>
get globalData
<button class="uni-common-mt" @click="_increasetLifeCycleNum">
increase lifeCycleNum
</button>
</button>
<text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
<template v-if="globalDataStr">
</view>
<text class="uni-common-mt">globalData str: {{ globalDataStr }}</text>
</view>
<text class="uni-common-mt">globalData num: {{ globalDataNum }}</text>
</template>
<text class="uni-common-mt">globalData boolean: {{ globalDataBool }}</text>
</template>
<script lang="uts">
<text class="uni-common-mt">点击按钮调用 App.uvue methods</text>
import { State, state, setLifeCycleNum } from '@/store/index.uts'
<text class="margin-top:6px;">increasetLifeCycleNum 方法</text>
<button class="uni-common-mt" @click="_increasetLifeCycleNum">
export default {
increase lifeCycleNum
data() {
</button>
return {
<text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
lifeCycleNum: 0,
</view>
}
</view>
},
</template>
onReady() {
this.lifeCycleNum = state.lifeCycleNum
<script lang="uts">
},
import { state, setLifeCycleNum } from '@/store/index.uts'
methods: {
_increasetLifeCycleNum: function () {
export default {
const app = getApp()
data() {
app.increasetLifeCycleNum()
return {
this.lifeCycleNum = state.lifeCycleNum
globalDataStr: '',
},
globalDataNum: 0,
// 自动化测试
globalDataBool: false,
setLifeCycleNum(num: number) {
lifeCycleNum: 0,
setLifeCycleNum(num)
}
},
},
},
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>
</script>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录