1:组件之间的通信
1:父组件向子组件
通过properties
2:子组件向父组件
通过 .triggerEvent()
2:页面之间通信
type1 : url之间的数据传递
a页面:
wx.navigateTo({
url: '/pages/my/index?name=' + data,
})
b页面:
onLoad:function(option){//接收数据
this.setData({
name: option.name
})
}
type2 : 全局globalData传值
a页面:
globalData: {
name:'hello world'
}
b页面:
onLoad:function(){
let name = app.globalData.name;
console.log(name);//hello world
}
type3 : 页面数据缓存wx.setStorageSync(KEY,DATA)
a页面:
wx.setStorage({
key:"name",
data:"hello world"
})
b页面:
onLoad:function(){
var value = wx.getStorageSync('name');
console.log(value);// hello world
}