Get the App
SLTechnology News&Howtos  ›  Development  › 

How to transfer values between parent and Child components in vue

Shulou Source: shulou.com Published: 2022-06-01 04:19:01 10月03日 Update

Editor to share with you how to achieve the value of vue parent-son components, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

Parent and child components pass values

The parent-child component passes the value {{total}} / / the parent component passes the value to the child component using props, plus the: sign is the js expression, in the example, it is a number, and without the: sign represents the string var counter = {/ / locally registered props: ['count'], data:function () {/ / defines data in the child component Data cannot be an object, it must be a function. Return {number:this.count}}, template:' {{number}}', methods: {handleClick2:function () {this.number + +; / / this.count++; parent components can pass values to child components, but child components cannot modify parent component properties. This.$emit ("numberchange", this.number) / / the child component passes events to the parent component. The value} var validateContent = {props: {/ / content: [Number,String] / / component parameter check You can select content: {/ / component parameters to verify type:String, required:true, default: "default value", validator:function (value) {return value.length > 5}, template:' {{content}}',} var vm = new Vue ({el:'#root', data: {total:0}) Methods: {handleChange:function (number) {console.log (number) / / this.total + = 1 }, components: {counter, / / partial registration to register the component validateContent}}) these are all the contents of the article "how to pass values between parent and child components in vue". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Components parents and children articles content parameters local not much events representatives functions most characters strings objects properties numbers data more knowledge examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Tech Info OPPO Reno Linux Microsoft