摘要: mpvue中页面之间传值(注意:是页面之间,不是组件之间)
场景:A页面跳转B页面,在B页面选择商品,将商品名带回A页面并显示
使用api: getCurrentPages
step1:
A页面js:
先定义一个全局的对象that,然后在mouted中把this赋给that
<script>
var that = null;
export default {
data () {
return {
setData: function (key,value) {
that[key] = value
}
}
},
}
<script>
mounted () {
that = this;
},
step2:
B页面js
getBrand (brand) {
let { from } = this.$root.$mp.query
let pages = getCurrentPages()
let page = pages.find( item => item.route.indexOf(from) != -1)
page.data.$root[0].setData('brand',brand)
wx.navigateBack({
delta: 1
});
}
讲解完毕,88, 下次见