提交 20540453 编写于 作者: W wanganxp

Merge branch 'dev' of https://gitcode.net/dcloud/hello-uni-app-x into dev

<template> <template>
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view style="flex:1;padding-bottom: 20px;"> <scroll-view style="flex: 1; padding-bottom: 20px">
<!-- #endif --> <!-- #endif -->
<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">get globalData</button> <button @click="getGlobalData">get globalData</button>
<template v-if="originGlobalData.str.length"> <template v-if="originGlobalData.str.length">
<text class="uni-common-mt bold">初始的 globalData:</text> <text class="uni-common-mt bold">初始的 globalData:</text>
<text class="uni-common-mt">globalData string: {{ originGlobalData.str }}</text> <text class="uni-common-mt">globalData string: {{ originGlobalData.str }}</text>
<text class="uni-common-mt">globalData number: {{ originGlobalData.num }}</text> <text class="uni-common-mt">globalData number: {{ originGlobalData.num }}</text>
<text class="uni-common-mt">globalData boolean: {{ originGlobalData.bool }}</text> <text class="uni-common-mt">globalData boolean: {{ originGlobalData.bool }}</text>
<text class="uni-common-mt">globalData object: {{ originGlobalData.obj }}</text> <text class="uni-common-mt">globalData object: {{ originGlobalData.obj }}</text>
<text class="uni-common-mt">globalData null: {{ originGlobalData.null }}</text> <text class="uni-common-mt">globalData null: {{ originGlobalData.null }}</text>
<text class="uni-common-mt">globalData array: {{ originGlobalData.arr }}</text> <text class="uni-common-mt">globalData array: {{ originGlobalData.arr }}</text>
<text class="uni-common-mt">globalData Set: {{ originGlobalData.mySet }}</text> <text class="uni-common-mt">globalData Set: {{ originGlobalData.mySet }}</text>
<text class="uni-common-mt">globalData Map: {{ originGlobalData.myMap }}</text> <text class="uni-common-mt">globalData Map: {{ originGlobalData.myMap }}</text>
<text class="uni-common-mt">globalData func 返回值: {{ originGlobalDataFuncRes }}</text> <text class="uni-common-mt">globalData func 返回值: {{ originGlobalDataFuncRes }}</text>
</template> </template>
<button @click="setGlobalData" class="uni-common-mt">set globalData</button> <button @click="setGlobalData" class="uni-common-mt">
<template v-if="newGlobalData.bool"> set globalData
<text class="uni-common-mt bold">更新后的 globalData:</text> </button>
<text class="uni-common-mt">globalData string: {{ newGlobalData.str }}</text> <template v-if="newGlobalData.bool">
<text class="uni-common-mt">globalData number: {{ newGlobalData.num }}</text> <text class="uni-common-mt bold">更新后的 globalData:</text>
<text class="uni-common-mt">globalData boolean: {{ newGlobalData.bool }}</text> <text class="uni-common-mt">globalData string: {{ newGlobalData.str }}</text>
<text class="uni-common-mt">globalData object: {{ newGlobalData.obj }}</text> <text class="uni-common-mt">globalData number: {{ newGlobalData.num }}</text>
<text class="uni-common-mt">globalData null: {{ newGlobalData.null }}</text> <text class="uni-common-mt">globalData boolean: {{ newGlobalData.bool }}</text>
<text class="uni-common-mt">globalData array: {{ newGlobalData.arr }}</text> <text class="uni-common-mt">globalData object: {{ newGlobalData.obj }}</text>
<text class="uni-common-mt">globalData Set: {{ newGlobalData.mySet }}</text> <text class="uni-common-mt">globalData null: {{ newGlobalData.null }}</text>
<text class="uni-common-mt">globalData Map: {{ newGlobalData.myMap }}</text> <text class="uni-common-mt">globalData array: {{ newGlobalData.arr }}</text>
<text class="uni-common-mt">globalData func 返回值: {{ newGlobalDataFuncRes }}</text> <text class="uni-common-mt">globalData Set: {{ newGlobalData.mySet }}</text>
</template> <text class="uni-common-mt">globalData Map: {{ newGlobalData.myMap }}</text>
<text class="uni-common-mt">点击按钮调用 App.uvue methods</text> <text class="uni-common-mt">globalData func 返回值: {{ newGlobalDataFuncRes }}</text>
<text class="margin-top:6px;">increasetLifeCycleNum 方法</text> </template>
<button class="uni-common-mt" @click="_increasetLifeCycleNum"> <text class="uni-common-mt">点击按钮调用 App.uvue methods</text>
increase lifeCycleNum <text class="uni-common-mt">increasetLifeCycleNum 方法</text>
</button> <button class="uni-common-mt" @click="_increasetLifeCycleNum">
<text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text> increase lifeCycleNum
</view> </button>
</view> <text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
<!-- #ifdef APP --> </view>
</scroll-view> </view>
<!-- #endif --> <!-- #ifdef APP -->
</template> </scroll-view>
<!-- #endif -->
<script lang="uts"> </template>
import { state, setLifeCycleNum } from '@/store/index.uts'
<script lang="uts">
type MyGlobalData = { import { state, setLifeCycleNum } from '@/store/index.uts'
str : string,
num : number, type MyGlobalData = {
bool : boolean, str : string,
obj : UTSJSONObject, num : number,
null : string | null, bool : boolean,
arr : number[], obj : UTSJSONObject,
mySet : string[], null : string | null,
myMap : UTSJSONObject, arr : number[],
func : () => string mySet : string[],
} myMap : UTSJSONObject,
func : () => string
export default { }
data() {
return { export default {
originGlobalData: { data() {
str: '', return {
num: 0, originGlobalData: {
bool: false, str: '',
obj: { num: 0,
str: '', bool: false,
num: 0, obj: {
bool: false str: '',
} as UTSJSONObject, num: 0,
null: null, bool: false
arr: [] as number[], } as UTSJSONObject,
mySet: [] as string[], null: null,
myMap: {}, arr: [] as number[],
func: () : string => '' mySet: [] as string[],
} as MyGlobalData, myMap: {},
originGlobalDataFuncRes: '', func: () : string => ''
newGlobalData: { } as MyGlobalData,
str: '', originGlobalDataFuncRes: '',
num: 0, newGlobalData: {
bool: false, str: '',
obj: { num: 0,
str: '', bool: false,
num: 0, obj: {
bool: false str: '',
} as UTSJSONObject, num: 0,
null: null, bool: false
arr: [] as number[], } as UTSJSONObject,
mySet: [] as string[], null: null,
myMap: {}, arr: [] as number[],
func: () : string => '' mySet: [] as string[],
} as MyGlobalData, myMap: {},
newGlobalDataFuncRes: '', func: () : string => ''
lifeCycleNum: 0, } as MyGlobalData,
} newGlobalDataFuncRes: '',
}, lifeCycleNum: 0,
onReady() { }
this.lifeCycleNum = state.lifeCycleNum },
}, onReady() {
methods: { this.lifeCycleNum = state.lifeCycleNum
getGlobalData() { },
const app = getApp() methods: {
getGlobalData() {
this.originGlobalData.str = app.globalData.str const app = getApp()
this.originGlobalData.num = app.globalData.num
this.originGlobalData.bool = app.globalData.bool this.originGlobalData.str = app.globalData.str
this.originGlobalData.obj = app.globalData.obj this.originGlobalData.num = app.globalData.num
this.originGlobalData.null = app.globalData.null this.originGlobalData.bool = app.globalData.bool
this.originGlobalData.arr = app.globalData.arr this.originGlobalData.obj = app.globalData.obj
app.globalData.mySet.forEach((value : string) => { this.originGlobalData.null = app.globalData.null
this.originGlobalData.mySet.push(value) this.originGlobalData.arr = app.globalData.arr
}) app.globalData.mySet.forEach((value : string) => {
app.globalData.myMap.forEach((value : any, key : string) => { this.originGlobalData.mySet.push(value)
this.originGlobalData.myMap[key] = value })
}) app.globalData.myMap.forEach((value : any, key : string) => {
this.originGlobalData.func = app.globalData.func this.originGlobalData.myMap[key] = value
this.originGlobalDataFuncRes = this.originGlobalData.func() })
}, this.originGlobalData.func = app.globalData.func
setGlobalData() { this.originGlobalDataFuncRes = this.originGlobalData.func()
const app = getApp() },
setGlobalData() {
app.globalData.str = 'new globalData str' const app = getApp()
app.globalData.num = 100
app.globalData.bool = true app.globalData.str = 'new globalData str'
app.globalData.obj = { app.globalData.num = 100
str: 'new globalData obj str', app.globalData.bool = true
num: 200, app.globalData.obj = {
bool: true str: 'new globalData obj str',
} num: 200,
app.globalData.null = 'not null' bool: true
app.globalData.arr = [1, 2, 3] }
app.globalData.mySet = new Set(['a', 'b', 'c']) app.globalData.null = 'not null'
app.globalData.myMap = new Map([ app.globalData.arr = [1, 2, 3]
['a', 1], app.globalData.mySet = new Set(['a', 'b', 'c'])
['b', 2], app.globalData.myMap = new Map([
['c', 3] ['a', 1],
]) ['b', 2],
app.globalData.func = () : string => { ['c', 3]
return 'new globalData func' ])
} app.globalData.func = () : string => {
return 'new globalData func'
this.newGlobalData.str = app.globalData.str }
this.newGlobalData.num = app.globalData.num
this.newGlobalData.bool = app.globalData.bool this.newGlobalData.str = app.globalData.str
this.newGlobalData.obj = app.globalData.obj this.newGlobalData.num = app.globalData.num
this.newGlobalData.null = app.globalData.null this.newGlobalData.bool = app.globalData.bool
this.newGlobalData.arr = app.globalData.arr this.newGlobalData.obj = app.globalData.obj
app.globalData.mySet.forEach((value : string) => { this.newGlobalData.null = app.globalData.null
this.newGlobalData.mySet.push(value) this.newGlobalData.arr = app.globalData.arr
}) app.globalData.mySet.forEach((value : string) => {
app.globalData.myMap.forEach((value : any, key : string) => { this.newGlobalData.mySet.push(value)
this.newGlobalData.myMap[key] = value })
}) app.globalData.myMap.forEach((value : any, key : string) => {
this.newGlobalData.func = app.globalData.func this.newGlobalData.myMap[key] = value
this.newGlobalDataFuncRes = this.newGlobalData.func() })
}, this.newGlobalData.func = app.globalData.func
_increasetLifeCycleNum: function () { this.newGlobalDataFuncRes = this.newGlobalData.func()
const app = getApp() },
app.increasetLifeCycleNum() _increasetLifeCycleNum: function () {
this.lifeCycleNum = state.lifeCycleNum const app = getApp()
}, app.increasetLifeCycleNum()
// 自动化测试 this.lifeCycleNum = state.lifeCycleNum
setLifeCycleNum(num : number) { },
setLifeCycleNum(num) // 自动化测试
} setLifeCycleNum(num : number) {
}, setLifeCycleNum(num)
} }
</script> },
}
<style> </script>
.bold {
font-weight: bold; <style>
} .bold {
font-weight: bold;
.hr { }
border-bottom: 1px solid #ccc;
} .hr {
border-bottom: 1px solid #ccc;
}
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册