zoukankan      html  css  js  c++  java
  • Vue 组件6内联模板

    如果子组件有inline-template特性,组件将把它的内容当做模板,而不是把它当做分发内容,这样模板更灵活。

    <my-component inline-template>
    <div>
    <p>These are compiled as the component's own template.</p>
    <p>Not parent's transclusion content.</p>
    </div>
    </my-component>
    但是,inline-template让模板的作用域难以理解,最佳实践是使用template选项在组件内定义模板或者在.vue文件中使用template元素。
     
    X-templates
    另一种定义模版的方式是在 JavaScript 标签里使用 text/x-template 类型,并且指定一个 id。例如:
    <script type="text/x-template" id="hello-world-template">
    <p>Hello hello hello</p>
    </script>
    Vue.component('hello-world', {
    template: '#hello-world-template'
    })
    这在有很多模版或者小的应用中有用,否则应该避免使用,因为它将模版和组件的其他定义隔离了。
    对低开销的静态组件使用v-once
    尽管在vue中渲染html非常快很快,不过当组件中包含大量静态内容时,可以考虑使用v-once,将渲染结果缓存起来,就像:
    Vue.component('terms-of-service', {
    template: '
    <div v-once>
    <h1>Terms of Service</h1>
    ... a lot of static content ...
    </div>
    '
    })
     
  • 相关阅读:
    取石子(二)巴仕博弈+尼姆博弈
    hdu2430Beans(单调队列)
    LCD: 2D-3D匹配算法
    如何选择视觉CV光源颜色
    gpgpu-sim卡分配程序设计实例分析
    PointRCNN: 点云的3D目标生成与检测
    3D点云重建原理及Pytorch实现
    GPU加速计算
    红外传感器技术
    Linux架构思维导图
  • 原文地址:https://www.cnblogs.com/susanws/p/7411437.html
Copyright © 2011-2022 走看看