vue-data passing

Components are the most powerful feature of Vue.js. Components can encapsulate reusable code, and realize the reuse of components by passing in different objects, but passing the value of components has become a problem that needs to be solved.

  1. Passing values ​​from parent component to child component The scope of a
    component instance is isolated. This means that the parent component's data cannot be directly referenced within the child component's template. To let the child component use the parent component's data, we need to pass the child component's props option.
    Child component:
    The child component needs to get the value of the logo from the parent component, it needs to use props: ['logo']
    The child component needs to get the value of the logo from the parent component, so you need to use props: ['logo'] The
    write picture description here
    parent component:
    write picture description here

  2. Child components pass values ​​to parent components
    Child components mainly pass data to parent components through events.
    Child component:
    write picture description here
    write picture description here
    where transferUser is a custom event, this.username will be passed to the parent component through this event.
    Parent component:
    write picture description here
    write picture description here
    The parameter msg in the getUser method is the parameter username passed from the child component

  3. When routed by
    write picture description here
    write picture description here
    value , it is assigned a value in the created life cycle.
    write picture description here

  4. Store data through localStorage or sessionStorage
    write picture description here

  5. When the application of Vuex
    is complex, it is recommended to use the vuex recommended by the vue official website.
    https://vuex.vuejs.org/en-us/getting-started.html

  6. Reference link
    http://blog.csdn.net/qq_32786873/article/details/70844811
    https://vuex.vuejs.org/zh-cn/getting-started.html
    https://segmentfault.com/a /1190000012123109

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325986213&siteId=291194637