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