Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does the vue child component use the value passed by the parent component

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how the vue child component uses the value passed by the parent component". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how the vue child component uses the value passed by the parent component.

The child component uses the value passed by the parent component import alarmstatistics from ". / alarmstatistics.vue"; components: {alarmstatistics,}, child component props: ["roless"], data () {return {role:this.roless,}, mounted () {if (this.role==3) {this.chartY = "9.5%";} else {this.chartY = "18%";}}

If you are using the value returned by the parent component interface, use the value directly in html

Props: ["infoDatac"] Application order number: {{item.applyCode}} usage time: {{item.useTime}} {{item.title}} Vue child component calls parent component data Child component: {{data}} / * data str in the parent component * bind the data of the parent component to the attribute data of the child component * and then receive it through props in the child component, * so that the value corresponding to the str1 of the parent component can be accessed by using the variable this.data1 in the child component. * / / when clicking on the child component, the changedata method of the child component is triggered by this.data = "the value of the parent component has been modified by the child component"; change the value of the parent str / / access the method fn () of the parent component through this.$parent.fn (). Var child= {props: ["data"], template: "# child", data:function () {return {str: "I am subcomponent data"}} Methods: {changedata:function () {this.data = "parent component value modified by child component" This.$parent.fn () } / * parent component * / var father= {template: "# father", data:function () {return {str: "I am the parent component data"}} Methods: {fn:function () {alert ("I am the parent component method")}}, components: {"mycomponentChild": child}} vm=new Vue ({/ / el: "# myVue" Components: {"myComponent": father}}). $mount ('# myVue') At this point, I believe you have a deeper understanding of "how the vue child component uses the value passed by the parent component". 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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report