About Vue method, followed by sub-components of the operating parent component data from the re-rendering of the page

Known, subassemblies, assemblies get the parent pass over the data by props, and this data can not be used in created, it mounted the life cycle, only to get in beforeUpdated or Updated ;

But if we want to use this data and then obtain additional data and render the page , we can not operate in beforeUpdated or updated, self-contradictory.

This method can be used in the Vue watch, listen first subassembly acquired data, when there is change data (that is, after acquiring the data to), and then call the appropriate method.

Below, detail the data obtained subassembly, and then to use this data in getTicket method, it is necessary to watch the monitor changes in detail, when the detail data, then call getTicket method, data used in the process

props: {
    detail: ''
  },
  methods: {
    async getTicket () {
      console(this.detail)
    }
  },
  watch: {
    detail () {
      this.getTicket()
    }
  }

 

Guess you like

Origin www.cnblogs.com/jane2160/p/11511933.html