小程序

globalData

1
2
3
4
5
6
7
8
9
10
11
12
// app.js
App({
globalData: {
userInfo: {
name: 'Luffy'
}
}
})

// abc.js
const app = getApp();
app.globalData.userInfo.name // Luffy

Component

1
2
3
4
5
6
7
Component({
data: {},
method: {
onLoad: {},
...
}
})

behaviors

seems to mixin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// my-behavior.js
module.exports = Behavior({
data: {
sharedText: 'abc'
},
methods: {
sharedMethod: function() {
this.data.sharedText === 'This is a piece of data shared between pages.'
}
}
})

// page-a.js
const myBehavior = require('./my-behavior.js')
Page({
behavior: [myBehavior],
onLoad: function() {
this.data.sharedText === 'This is a piece of data shared between pages.'
}
})

本文作者: 孟 虎
本文链接: https://menghu1994.github.io/blog/2023/10/Applet/index/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!