[英]Vue JS 2: Stop lifecycle after beforeCreate
No. There are other ways to prevent a component from rendering不,还有其他方法可以阻止组件渲染
v-if
Use v-if
in the parent to conditionally render.在父级中使用v-if
有条件地渲染。
<child v-if="shouldRender"></child>
data: () => ({
shouldRender: false
})
beforeRouteEnter
If the component is a router page, you can prevent it from being created with the beforeRouteEnter
navigation guard.如果该组件是一个路由页面,您可以使用beforeRouteEnter
导航守卫来阻止它被创建。
beforeRouteEnter (to, from, next) {
if (something) {
// Don't render the component, go somewhere else
next({ path: '/somewhere' });
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.