【微信小程序】mpvue中页面之间传值(全网唯一真正可行的方法,中指推了一下隐形眼镜)

摘要: 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

 

1     getBrand (brand) {
2       let { from } = this.$root.$mp.query
3       let pages = getCurrentPages()
4       let page = pages.find( item => item.route.indexOf(from) != -1)
5       page.data.$root[0].setData('brand',brand)
6       wx.navigateBack({
7         delta: 1
8       });
9     }

 

 

 

讲解完毕,88, 下次见

posted @ 2019-07-17 18:54  等一轮新月  阅读(2003)  评论(5编辑  收藏  举报