1👍
You can use props.
<component-1 v-bind:message="mydata"></component-1>
Then in your child component (directly from the docs):
Vue.component('component-1', {
// declare the props
props: ['message'],
// just like data, the prop can be used inside templates
// and is also made available in the vm as this.message
template: '<span>{{ message }}</span>'
})
- [Vuejs]-Vue js – making a style to be inherited by children components
- [Vuejs]-How to pass a template variable to event handler method in Vue js
0👍
Rather than using props (which might mean you have to pass around those props a lot) you can access variables using $parent (or $root)
Vue.component('component-1', {
computed: {
message: function(){
// this is how to access the variable inside the component code
return this.$parent.message;
},
},
// and because of using computed, access it inside the template
template: '<span>{{ message }}</span>'
})
- [Vuejs]-How to emit event in Vue.js depending on the width of the screen
- [Vuejs]-Passing props/attribute to nested component inside custom component
-1👍
You just importing some not inherited components, so you can’t share data like that.
Add components into components field in parent component like here:
https://v2.vuejs.org/v2/guide/components.html#Local-Registration
Then in child components you can use this.$parent. And this.$parent.mydata in your example
- [Vuejs]-How to create a Vue Tooltip component using BootstrapVue tooltip
- [Vuejs]-Nuxt.js generate and Three.js – SyntaxError: Cannot use import statement outside a module
Source:stackexchange.com