Question:
Is there any way to update the props of a manually mounted vue component/instance that is created like this? I'm passing in an object called item
as the component's data
prop.
let ComponentClass = Vue.extend(MyComponent);
let instance = new ComponentClass({
propsData: { data: item }
});
// mount it
instance.$mount();
Why
I have a non vue 3rd party library that renders content on a timeline (vis.js). Because the rest of my app is written in vue I'm attempting to use vue components for the content on the timeline itself.
I've managed to render components on the timeline by creating and mounting them manually in vis.js's template function like so.
template: function(item, element, data) {
// create a class from the component that was passed in with the item
let ComponentClass = Vue.extend(item.component);
// create a new vue instance from that component and pass the item in as a prop
let instance = new ComponentClass({
propsData: { data: item },
parent: vm
});
// mount it
instance.$mount();
return instance.$el;
}
item.component
is a vue component that accepts a data prop.
I am able to create and mount the vue component this way, however when item
changes I need to update the data
prop on the component.
render
function for the parent that causes your dynamic new component to display. That is how you properly hook up props.propsData
is unchangeable and intended for testing creation. – BatangaspropsData
? I don't have the option of mounting this component in a render function because its being passed into a 3rd party library (that is not vue). – Chemnitzitem
is an object whose members' values are changing, you could set thedata
function to returnitem
and probably get what you want. – Batangas