1. Parent component passes value to child component1. Parent component.vue// <template> in parent component <div> <Child ref="child" :title="value"/> </div> </template> <script> export default { data() { return { value: 'hello world!' } } } </script> 2. Subcomponent.vue// <template> in parent component <div> <span>{{title}}</span> </div> </template> <script> export default { props: { title: type: String, default: '' } } } </script> //The title value is 'hello world! 2. Values can also be transferred between sibling components through the middleware Bus 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. Subcomponents pass values to parent components1. Parent component.js<template> <div> <Child ref="child" @getTitle="getTitle"/> </div> </template> <script> import Child from './components/Child' export default { components: Child }, data() { return { } }, method:{ getTitle(data){ console.log(data) } } } </script> The print result is 2. Subcomponent.js<template> <div> <span>{{title}}</span> </div> </template> <script> export default { data() { return { title: 'hello xuliting' } }, mounted(){ this.getFun() }, method:{ getFun(){ this.$emit("getTiltle",this.title) } } } </script> Summarize:The problem can also be solved by transferring methods between components. For example, the parent component is A, and the child components are B and C. The method that parent component A calls child component B is defined as aFun, and aFun is passed to child component C. This is the method passed to component C in the parent component <C :a-fun="aFun" /> The reference is in component C, through props props: { aFun: { type: Function, default: () => function() {} } } This article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: The difference between VOLUME and docker -v in Dockerfile
>>: How many pixels should a web page be designed in?
CSS to achieve the image hovering mouse folding e...
Detailed explanation of JDBC database link and re...
1. Horizontal center Public code: html: <div c...
This article example shares the specific code of ...
ask: I have styled the hyperlink using CSS, but i...
There are many tags in XHTML, but only a few are ...
Installation Environment Description •System vers...
1. Vertical table and horizontal table Vertical t...
1. Alipay method: Alipay method: Click Alipay to ...
Table of contents 1. Security issues with Docker ...
Table of contents What is async? Why do we need a...
Table of contents 1. Function definition 1.1 Func...
Swap space is a common aspect of computing today,...
Preface When my team was developing the tax syste...
First create a specific project directory for you...