I want to update data in a component from my Vue instance. Finding plenty of examples on how to do the opposite, but nothing on this.
Say I have:
Vue.component('component', {
props: {
prop: {
default: null
}
},
template: '#template',
data: function () {
return {
open: false
};
}
});
Now I would like to set open to true from my Vue instance:
var root = new Vue({
el: '#root',
data: {},
methods: { updateComponentData: function() {//set open to true} } });
rootin your example) to update a child component (componentin your example)? If so, it's highly recommended to follow a pattern where data is passed down from the parent to the child and events are passed up from the child to the parent (more in Vue's documentation). In your example, your child would have apropcalledopenand your parent would bind the value representing theopenstate to the child component.opento be apropyou actually get a vue warning telling you it should be data. Either way, as you say I try to pass data from instance (root) to component (component). But they are seperate, so not sure if it counts as parent-child. i.e the component does not exist inside the vue instance. If you think you have a solution please post an answer because I've spent hours in the docs you linked with no real success.opento be apropyou actually get a vue warning telling you it should be data" – would you expand your question to include this attempt? I would not expect Vue attempting to warn you regarding this.<div>...<child-component>...</child-component>...</div>.