Parent Component:
<template>
<div id="user">
Hello there! {{msg}} {{name}}
You have below messages
<Message v-for='(msg,index) in messages'
:messageText='msg'
:messageNumber='index+1'
:welcome-msg='{{msg}}'></Message>
</div>
</template>
<script>
import Message from "./Message.vue";
export default {
data () {
return {
msg: 'Welcome dear',
name: 'Max',
messages: [ 'Message 1', 'Message 2']
}
},
components: {
Message
}
}
</script>
Child Component:
<template>
<div>
{{messageNumber}}. {{messageText}} - {{welcomeMsg}}
</div>
</template>
<script>
export default {
props: {
messageNumber: Number,
messageText: String,
welcomeMsg: String
}
}
</script>
I am trying to pass the data msg ('Welcome dear') from parent to the child. Is there a way to specify to access the parent msg for welcome-msg prop ?
Note: I am aware that I can make it work by changing the v-for like. I have just started learning Vue.js and curious to know if there is a way to access parent's data through some sort of scoping
<Message v-for='(item,index) in messages'
:messageText='item'
:messageNumber='index+1'
:welcome-msg='msg'></Message>
Update: This is not a duplicate of variable shadowing, as with variable shadowing there is a way to invoke the global function using window.functionName. This question is specific to Vue.js & hence I am not convinced this is a duplicate.