提交 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,15 +2,14 @@
<view>
<page-head title="getApp"></page-head>
<view class="uni-padding-wrap">
<button @click="getGlobalData">
get globalData
</button>
<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>
<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>
<text class="uni-common-mt">globalData boolean: {{ globalDataBool }}</text>
</template>
<text class="uni-common-mt">点击按钮调用 App.uvue methods</text>
<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
......@@ -27,7 +26,7 @@
data() {
return {
globalDataStr: '',
globalDataNum: 0,
globalDataNum: 0,
globalDataBool: false,
lifeCycleNum: 0,
}
......@@ -39,9 +38,15 @@
getGlobalData() {
const app = getApp()
this.globalDataStr = app.globalData.str
this.globalDataNum = app.globalData.num
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.
先完成此消息的编辑!
想要评论请 注册