How to understand the value passed by vue father and son, brother and son
This article mainly explains "how to understand vue father-son value, brother value, son father value", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to understand vue father and son value, brother value, son father value" bar!
The parent component passes a value of 1 to the child component. Export default {data () {return {value: 'hello worldview'}} in parent component .vue / / parent component 2. Child component .vue / / parent component {{title}} export default {props: {title: {type: String, default:''}
/ / title value is' hello world!
Second, the values between sibling components can also be transferred through the middleware Bus.
$emit pass value
$on receive
$off delete transfer event
1.A component .jsthis. $bus.$emit ("flag", true) 2.B component .jsmounted () {this.$bus.$off ('flag') this.$bus.$on (' flag', data= > {this.flag= data})} 3. The child component passes the value 1 to the parent component. Parent component .js import Child from'. / components/Child'export default {components: {Child}, data () {return {}}, method: {getTitle (data) {console.log (data)}
The print result is hello xuliting
two。 Child component .js {{title}} export default {data () {return {title: 'hello xuliting'}}, mounted () {this.getFun ()}, method: {getFun () {this.$emit ("getTiltle", this.title)}, I believe you have a deeper understanding of "how to understand vue father-son value, brother value, child father value". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!