摘要: 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, 下次见