提交 3d2e654b 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat: 补充 globalData 示例及测试

上级 f4f42962
......@@ -8,10 +8,16 @@ describe('getApp', () => {
})
it('globalData', async () => {
await page.callMethod('getGlobalData')
const data = await page.data()
let data = await page.data()
expect(data.globalDataStr).toBe('global data str')
expect(data.globalDataNum).toBe(123)
expect(data.globalDataBool).toBe(true)
await page.callMethod('setGlobalData')
await page.callMethod('getGlobalData')
data = await page.data()
expect(data.globalDataStr).toBe('new global data str')
expect(data.globalDataNum).toBe(456)
expect(data.globalDataBool).toBe(false)
})
it('method', async () => {
const oldLifeCycleNum = await page.data('lifeCycleNum')
......
......@@ -2,9 +2,8 @@
<view>
<page-head title="getApp"></page-head>
<view class="uni-padding-wrap">
<button @click="getGlobalData">
get globalData
</button>
<button @click="getGlobalData">get globalData</button>
<button @click="setGlobalData" class="uni-common-mt">set globalData</button>
<template v-if="globalDataStr">
<text class="uni-common-mt">globalData str: {{ globalDataStr }}</text>
<text class="uni-common-mt">globalData num: {{ globalDataNum }}</text>
......@@ -42,6 +41,12 @@
this.globalDataNum = app.globalData.num
this.globalDataBool = app.globalData.bool
},
setGlobalData() {
const app = getApp()
app.globalData.str = 'new global data str'
app.globalData.num = 456
app.globalData.bool = false
},
_increasetLifeCycleNum: function () {
const app = getApp()
app.increasetLifeCycleNum()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册