How can I update properties of a Vue component from outside? #15176
|
Hello! I'm creating a micro-frontends library, and I would like to know if I can update properties of a Vue component that I create using This is what I have used for experimenting, but doesn't work: import { ref, reactive, createApp, triggerRef } from 'vue'
const msg = ref('Hi!');
const r = reactive({ msg });
const app = createApp(App, r);
const mounted = app.mount('#app');
console.log('Props: ', mounted.$props);
setTimeout(() => {
console.log('msg: ', msg.value);
msg.value = 'Hello!';
// triggerRef(msg);
console.log('msg: ', msg.value);
console.log('Props: ', mounted.$props);
// mounted.$forceUpdate();
}, 4000);The idea here would be to create generic code that receives the component and the list of initial properties as arguments, then mount the component, and then wait for any requested changes in the properties, but the user interface is not changing. I must note, however, that the updated Does anybody know how I can set this up? |
Replies: 1 comment 2 replies
|
Ok, I may have found the answer: import { reactive, createApp, h } from 'vue'
import App from './App.vue'
const r = reactive({ msg: 'hi' });
const app = createApp({
render: () => h(App, r)
});
const mounted = app.mount('#app');
console.log('Props: ', mounted.$props);
setTimeout(() => {
console.log('msg: ', r.msg);
r.msg = 'Hello!';
console.log('msg: ', r.msg);
}, 4000);This works. If anyone knows of a better way to do this, I'll be most grateful. I'll be also grateful for any links to information about the subject. I did read Reactivity in Depth in the docs, but it doesn't show you how to set things up from "outside". |
Ok, I may have found the answer:
This works. If anyone knows of a better way to do this, I'll be most grateful. I'll be also grateful for any links to information about the subject. I did read Reactivity in Depth in the docs, but it doesn't show you how to set things up from "outside".