【Vue】is特性

22 篇文章 0 订阅

1.限制元素

Vue模板就是dom模板,而dom对一些html元素是有限制的,比如

<table>
	<my-component></my-component>
</table>

这样是不行的
通过is我们可以拓展html元素,比如

<ul>
  <li is="my-component"></li>
</ul>

2.动态组件

通过is我们可以动态的更换模板中的组件

<div id="app">
    <component :is="currentView"></component>
    <button @click="handleChangeComponent('component-one')">A</button>
    <button @click="handleChangeComponent('component-two')">B</button>
</div>
 var app = new Vue({
     el: '#app',
     components:{
       component-one:{
         template:`
           <div>组件一</div>
            `
       },
       component-two:{
          template:`
            <div>组件二</div>
             `
       },
     },
     data:{
        currentView:'component-one'
     },
     methods:{
        handleChangeComponent:function(component){
           this.currentView = component;
        }
     }
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值