Comments (7)
You can do like this.
const app = Vue.createApp()
app.mount(Root, document.getElementById('app'))
setTimeout(() => {
// equal to $destroy
Vue.render(null, document.getElementById('app') )
}, 1000)
from core.
Maybe should add some api like unmount
.
from core.
You can do like this.
const app = Vue.createApp() app.mount(Root, document.getElementById('app')) setTimeout(() => { // equal to $destroy Vue.render(null, document.getElementById('app') ) }, 1000)
用这个方法可以实现 unmount
效果, 成功触发了 vue 组件的 beforeUnmount
。
谢了。
from core.
In Vue3, I tried the following code, and it can unmount an component (not the whole app):
<router-view v-slot="{Component, route}">
<keep-alive ref="keepAlive"><component :key="route.path" :is="Component" /></keep-alive>
</router-view>
onCloseTab(targetName) {
const route = this.tabRoutes.find(route => targetName === route.params.f_id)
this.$store.dispatch('removeTab', targetName)
// 删除组件在keepalive里的cache,参考 pruneCacheEntry 这个方法的逻辑
const key = route.path
const keepAliveInstance = this.$refs.keepAlive.$
const cache = keepAliveInstance.__v_cache
const vnode = cache.get(key)
if (vnode) {
let shapeFlag = vnode.shapeFlag
if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {
shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */
}
if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {
shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */
}
vnode.shapeFlag = shapeFlag
const renderer = keepAliveInstance.ctx.renderer
renderer.um(vnode, keepAliveInstance, keepAliveInstance.suspense)
cache.delete(key)
}
}
this.$.ctx.renderer.um(vnode, keepAliveInstance, keepAliveInstance.suspense)
from core.
在 Vue3 中,我尝试了以下代码,它可以卸载一个组件(不是整个应用程序):
<router-view v-slot="{Component, route}"> <keep-alive ref="keepAlive"><component :key="route.path" :is="Component" /></keep-alive> </router-view>
onCloseTab(targetName) { const route = this.tabRoutes.find(route => targetName === route.params.f_id) this.$store.dispatch('removeTab', targetName) // 删除组件在keepalive里的cache,参考 pruneCacheEntry 这个方法的逻辑 const key = route.path const keepAliveInstance = this.$refs.keepAlive.$ const cache = keepAliveInstance.__v_cache const vnode = cache.get(key) if (vnode) { let shapeFlag = vnode.shapeFlag if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) { shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */ } if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) { shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */ } vnode.shapeFlag = shapeFlag const renderer = keepAliveInstance.ctx.renderer renderer.um(vnode, keepAliveInstance, keepAliveInstance.suspense) cache.delete(key) } }
this.$.ctx.renderer.um(vnode, keepAliveInstance, keepAliveInstance.suspense)
After the project is packaged, keepAliveInstance.__v_cache does not get the value
from core.
In Vue3, I tried the following code, and it can unmount an component (not the whole app):
<router-view v-slot="{Component, route}"> <keep-alive ref="keepAlive"><component :key="route.path" :is="Component" /></keep-alive> </router-view>
onCloseTab(targetName) { const route = this.tabRoutes.find(route => targetName === route.params.f_id) this.$store.dispatch('removeTab', targetName) // 删除组件在keepalive里的cache,参考 pruneCacheEntry 这个方法的逻辑 const key = route.path const keepAliveInstance = this.$refs.keepAlive.$ const cache = keepAliveInstance.__v_cache const vnode = cache.get(key) if (vnode) { let shapeFlag = vnode.shapeFlag if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) { shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */ } if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) { shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */ } vnode.shapeFlag = shapeFlag const renderer = keepAliveInstance.ctx.renderer renderer.um(vnode, keepAliveInstance, keepAliveInstance.suspense) cache.delete(key) } }
this.$.ctx.renderer.um(vnode, keepAliveInstance, keepAliveInstance.suspense)
after build not find __v_cache
from core.
vue2 in nuxt, 为何调用根结点的 vm.$destroy()
方法只能销毁vm, 却不能从DOM中移除mount 的DOM?
from core.
Related Issues (20)
- "Unhandled error during execution of render function" when decreasing an array size HOT 3
- 模板中 定义 异步箭头函数, 并在函数内部将 (其他)异步函数返回值赋值, 出现 ` 'await' is only allowed within async functions and at the top levels of modules.` HOT 2
- Lazy loading images only works on first load HOT 2
- The search function of the Chinese official website is not available HOT 6
- defineModel does not preserve all runtime types in prod when types contain boolean HOT 5
- TypeError: Cannot read properties of null (reading '0') in product mode HOT 19
- Storing the props in a `const` before passing them in `h` function causes reactivity problems HOT 2
- The slots objectless prototype function obtained by useSlots HOT 12
- Unhandled error during execution of setup function at <App>:Maximum call stack size exceeded HOT 3
- computed function executed with in an error HOT 2
- v-model does not trigger emit on input number when native functions stepUp/stepDown are called HOT 2
- SFC playground crashed after renaming a file HOT 1
- On hot reload: "VueCompilerError: Element is missing end tag." HOT 1
- `toRaw(attrs)` is not a plain object anymore in ^3.4.22 HOT 8
- 中文文档官网搜索不好用 HOT 2
- Putting a ref inside a ref should unwrap it, but its possible to trick the build system so it still thinks its a ref. HOT 1
- Activated lifecycle hook not triggered in async context HOT 5
- 组件的字面量prop的监听被意外触发 HOT 3
- Unhandled error during execution of scheduler flush. This is likely a Vue internals bug. HOT 6
- A type for a vnode as the first argument of h() is missing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.