设为首页 加入收藏
您当前位置 > 中商网 > 家居 > 正文
>
分享
新浪微博
腾讯微博
微信
QQ空间
QQ好友
手机阅读分享话题

Vue单页面的动态组件

2020-03-23 06:24:42阅读: 来源:
<template id="my-A">
<div>
<p >{{title}}</p>
</div>
</template>
<template id="my-B">
<div>
<p >B组件</p>
</div>
</template>
<template id="my-C">
<div>
<p >C组件</p>
</div>
</template>
<div id="app">
<!-- 动态组件 一-->
<button @click="flag= 'a'">a组件</button>
<button @click="flag= 'b'">b组件</button>
<my-a v-if="flag=='a'" :title=" 'aaaa组件' "></my-a>
<my-a v-if="flag=='b'" :title=" 'bbbb组件' "></my-a>
<hr>
<!-- 动态组件 二 判断的是组件的名称-->
<button @click="flag2= 'my-b'">b组件</button>
<button @click="flag2= 'my-c'">c组件</button>
<component :is="flag2"></component>
</div>

<script>
new Vue({
el:'#app',
data:{
flag:'a',
flag2:'my-b'
},
components:{ //组件
'my-a':{
template:'#my-A',
props:['title']
},
'my-b':{
template:'#my-B',
},
'my-c':{
template:'#my-C',
}
}
});
</script>

(正文已经结束)

推荐阅读:苹果x跟xr

免责声明及提醒:此文内容为本网所转载企业宣传资讯,该相关信息仅为宣传及传递更多信息之目的,不代表本网站观点,文章真实性请浏览者慎重核实!任何投资加盟均有风险,提醒广大民众投资需谨慎!