[Micro] applet letter by value between the pages mpvue (the only truly viable method for the whole network, the middle finger push of a contact lens)

Abstract: pass values ​​between pages mpvue (Note: It is between the pages, not the component between)

Scene: A B page jump page, select the page B goods, the trade name back to the A page and displays

使用api: getCurrentPages 

 

step1:

A page js:

Define a global object that, and then assign that this mouted in the

 

<script>
var that = null;
export default {
  data () {
    return {
      setData: function (key,value) {
        that[key] = value
      }
    }
  },
}
<script>

 

  mounted () {
    that = this;
  },

 

 

step2: 

B page 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     }

 

 

 

Explain finished, 88, see you next time

Guess you like

Origin www.cnblogs.com/yfgg/p/11203004.html