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.
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, so you need to use props: ['logo'] The
parent component:
Child components pass values to parent components
Child components mainly pass data to parent components through events.
Child component:
where transferUser is a custom event, this.username will be passed to the parent component through this event.
Parent component:
The parameter msg in the getUser method is the parameter username passed from the child componentWhen routed by
value , it is assigned a value in the created life cycle.
Store data through localStorage or sessionStorage
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.htmlReference link
http://blog.csdn.net/qq_32786873/article/details/70844811
https://vuex.vuejs.org/zh-cn/getting-started.html
https://segmentfault.com/a /1190000012123109