vued动态组件

今天在做tab组件的时候,偶然发现component动态组件的用法,由于平时基本没用,都忘了还有它的存在了,一翻文档,发现还特别好用,看来以后还是要多用用了。

话不多说,直接上代码:

1
2
3
4
5
6
7
<button @click="componentName='first'">组件2</button>
<button @click="componentName='second">组件2</button>
//这里是重点
<component :is="componentName"></component>

import first from "@/components/first"
import second from "@/components/second"

当动态改变componentName的值时,就可以渲染不同的组件内容了。


上一篇
nodejs全局对象 nodejs全局对象
__filename 当前执行脚本的文件名__dirname 当前执行脚本所在的文件目录setTimeout()clearTimeout()setInterval()clearInterval()console.log()123consol
2019-07-09
下一篇
vue打包后溢出隐藏代码失效 vue打包后溢出隐藏代码失效
今天碰到一个小坑,vue项目在打包后,溢出隐藏,出现省略号的代码竟然失效了,必须加上123/*! autoprefixer: off */ -webkit-box-orient: vertical; /* autoprefixe
2019-01-23 刘赛