【发布时间】:2022-01-16 10:05:08
【问题描述】:
我在帧加载期间安装了一个 Vue 3 组件作为加载动画:
createApp(App).mount(e);
加载框架时,框架内容会在 html 中删除组件(但我猜不是 Vue)。此行为由 Vue 的外部系统管理。
当我尝试使用相同的命令重新加载组件时,该组件不显示。
如果我只重新挂载该组件,我会在控制台中出现以下警告并且该组件不会显示:
"[Vue warn]: App has already been mounted.
If you want to remount the same app, move your app creation logic into a factory function and create fresh app instances for each mount - e.g. `const createMyApp = () => createApp(App)`".
我还找到了一种复制问题的方法:
const app = createApp(App)
app.mount(el);
el.innerHtml = '';
app.mount(el);
我也尝试卸载组件,但没有成功:
const app = createApp(App);
app.mount(el);
app.unmount();
app.mount(el);
那么在外部擦除同一个 vue 组件时,再次显示它的正确方法是什么?
【问题讨论】: