vue基础(续)

学无止境,望君把握时间!

1.动态组件:

动态组件就是 component组件   , 组件身上可以绑定一个is属性, 用来表示某一个组件
1.is属性:
---我们html中有一些标签是规定它的直接子元素的 , 比如 ul li ol li selector option 
table这类型标签
---不能直接用常规的组件使用方式, 必须在对应直接子元素上绑定 is属性
2.keep-alive组件
将组件的内容存在浏览器缓存中, 当我们需要重复渲染的时候, 就从浏览器缓存中去调用,
这样可以减少性能消耗
```javascript
上面的问题可以用这种方法来解决。
<div id="app">
      <table>
        <tr>
          <td>aa</td>
          <td>bb</td>
          <td>cc</td>
        </tr>
        <!-- is = 组件名称 -->
        <tr is = 'my-table'></tr>
      </table>
</div>
```javascript
举例:
<div id="app">
   <keep-alive>
      <component is = "B"></component>
   </keep-alive>
</div>
<script>
  new Vue({
     el : '#app',
     components : {
       'A' : {
          template : '<div>A</div>'
       },
       'B' : {
          template : '<div>B</div>'
       }
     }
  })
</script>
深入一点:
<div id = "app">
   <button @click = "type === type ? B: A"></button>
   <component is = "type"></component>
</div>
<script>
  new Vue ({
    el : '#app',
    data : {
      type : 'A'
    },
    components : {
      'A' : {
         template : '<div> A </div>'
      },
      'B' : {
         template : '<div> B </div>'
      }
    }
  })
</script>

2.不常用指令:

 - 1.v-text vs v-html
 - -都是用来将数据插入到DOM中,但是v-html可以解析标签类型数据
 - 2.v-cloak  解决 {{}} 语法短暂原样输出
 - 3.v-pre  原样输出
 - 4.v-once 只渲染一次

异步组件:

核心:异步组件也是一个函数, 只不过这个函数使用Promise,函数有一个返回值
<div id = "app">
    <async-com></async-com>
</div>
<script>
  var result = new Promise((resolve, reject) =>{
      resolve ({
         template : '<div>异步组件</div>'
      })
  })
  Vue.component('AsyncCom', async ()=>{
     var tep = await result.then(res => res);
     return tep
  })
  new Vue({
     el : '#app'
  })
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值