关于Vue中:is作用的浅析

1.:is特性进行动态内容切换

<div id="app">
    <button @click="changeComponent('component1')">A</button>
    <button @click="changeComponent('component2')">B</button>
    //点击按钮进行数据切换
    <div :is="currentView"></div>
    //内容展示的地方
     
</div>

//引入组件
import component1 from '../component1';
import component2 from '../compnent2';

export default {
 data(){
 return {
    currentView:'component1'
     //当前组件(默认组件)
  } 
 },
 methods:{
     changeComponent(component){
     this.currentView=component;
         //通过点击不同的按钮对currentVIew进行不同的赋值,从而达到内容的变化
    }
 }
 components:{
     component1,
     component2
 }
} 

2.解析DOM模板 : 解除限制元素
有些 HTML 元素,诸如 <ul、<ol、<table 和 <select,对于哪些元素可以出现在其内部是有严格限制的。而有些元素,诸如 <li、<tr 和 <option,只能出现在其它某些特定的元素内部。

这会导致我们使用这些有约束条件的元素时遇到一些问题。

<table>
      <my-component></my-component>
</table>
<!-- 这个自定义组件<my-component>会被作为无效的内容提升到外部,并导致最终渲染结果出错。 -->

<table> <tr is="my-component"></tr> </table> <!--增加is特性来扩展,从而达到可以在这些受限制的html元素中使用 -->
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值