In Vue, how do I get the emitted value from a child component and then use it in the parent component's return data?
P粉523625080
P粉523625080 2023-12-19 20:43:06
0
1
371

How to get the title value passed by the Topbar component and use the value in the data() return part? I tried adding a method to pass the value, but unfortunately, although I was able to console log the value in the parent file, it didn't work. I'm still a beginner in vue js so I'd like some help on this issue. Thanks!

 

Top bar template

 

P粉523625080
P粉523625080

reply all (1)
P粉667649253

Try a code snippet like below (pass all tabs to child and loop there):

const app = Vue.createApp({ data() { return { title:'', tabs: [ {link:'', name: "Sec 1", dropdown: false, dropdownTabs:[]}, {link:'', name: "Sec 2", dropdown: false, dropdownTabs:[]} ] } }, methods: { getTabTitle(title) { console.log(title) this.title =title } } }) app.component('topbar', { template: ` 
`, props: ['tabs'], methods: { send(title) { this.$emit('passData', title) } } }) app.mount('#demo')
 
{{ title }}
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!