动态地从组件切换到标签
Dynamically switching from component to tag
在Vue中是否可以在组件和标签之间切换,就像我们可以在组件之间切换一样?
<component :is="component"></component>
我的情况:如果指定了路径,我希望用 router-link
标记包裹一个按钮组件,如果没有路径,它将是一个简单的 div
.
编写计算 属性“组件”并处理应使用的标签
computed:{
component(){
if(// has path)
return RouterLink;
else
return 'div';
}
}
在Vue中是否可以在组件和标签之间切换,就像我们可以在组件之间切换一样?
<component :is="component"></component>
我的情况:如果指定了路径,我希望用 router-link
标记包裹一个按钮组件,如果没有路径,它将是一个简单的 div
.
编写计算 属性“组件”并处理应使用的标签
computed:{
component(){
if(// has path)
return RouterLink;
else
return 'div';
}
}