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

feat: 补充 globalData 示例及测试

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