如果子组件有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>\
'
})
 

Vue 组件6内联模板的更多相关文章

  1. vue 组件高级用法(递归组件,内联模板,动态组件,异步组件)

  2. Vue 内联模板(inline-template)

    内联模板不会把子组件的内容分发渲染到父组件中 而是需要在父组件中实现其内容的渲染 父组件 <template> <div> <template-inline inline ...

  3. 内联模板、X-Template

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <script s ...

  4. Vue.js style(内联样式)

    Vue.js style(内联样式) 我们可以在 v-bind:style 直接设置样式: <div id="app"> <div v-bind:style=&q ...

  5. Vue.js绑定内联样式

    1.对象语法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

  6. vue 组件 单选切换控制模板 v-bind-is

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>T ...

  7. vue.js中内联样式style三元表达式

    <span v-bind:style="{'display':config.isHaveSearch ? 'block':'none'}" >搜索</span&g ...

  8. vue组件详解(五)——组件高级用法

    一.递归组件 组件在它的模板内可以递归地调用自己, 只要给组件设置name 的选项就可以了. 示例如下: <div id="app19"> <my-compone ...

  9. Vue组件的is具体用法

    1.为什么要使用is 在vue的官网组件部分中,有明确的描述:当使用 DOM 作为模板时 (例如,使用 el 选项来把 Vue 实例挂载到一个已有内容的元素上),你会受到 HTML 本身的一些限制,因 ...

随机推荐

  1. 【记忆化搜索】bzoj1048 [HAOI2007]分割矩阵

    标准差=√(Σ(xi-xba)2/n)=Σ(xi)2+xba*n-2*xba*sum.只需最小化每个分割出来的矩阵的平方和即可. #include<cstdio> #include< ...

  2. 使用Python的turtle模块画出简单的柱状图

    代码如下: import turtle heights = [856, 420,360,260,205] def main(): t = turtle.Turtle() t.hideturtle() ...

  3. 表或视图不存在 Hibernate Oracle

    曾经运行一个别人写的程序,之前连的别人的机器的数据,后来我把数据导入到本地数据库中运行,出错,如下:Hibernate: select sum(rdb_alert_0_.EVENT_COUNT) as ...

  4. android线程及线程池

    众所周知,在UI系统中进行一些耗时操作,都会导致卡顿现象,因为一次刷新在16ms,如果当次操作过了这个时间,那么用户就能感觉到明显的卡顿,甚至引起ANR . 对于这种情况,一般都是再起一个线程,进行一 ...

  5. sun.misc.BASE64Decoder导入异常及处理思路

    Java后台保存base64图片数据 使用byte[] bytes = new BASE64Decoder().decodeBuffer(str);需要引入sun.misc.BASE64Decoder ...

  6. JS中的Math.pow(a,b)方法

    定义和用法 pow() 方法可返回 x 的 y 次幂的值. 语法 Math.pow(x,y) 参数 描述 x 必需.底数.必须是数字. y 必需.幂数.必须是数字. 返回值 x 的 y 次幂. 说明 ...

  7. linux基础-第十八单元_nginx部署

    一.基本环境配置 1.1.安装常用软件 yum install wget -y 1.2.Install yum repo mv /etc/yum.repos.d/CentOS-Base.repo /e ...

  8. Gitlab系列九之取消用户注册页面和删除用户

    一.取消用户注册页面 Admin Area--->Settings--->Sign-up enabled(取消前面的勾)---save 二.删除用户 Users----Destroy(点他 ...

  9. javascript快速入门19--定位

    元素尺寸 获取元素尺寸可以使用下面几种方式 元素的style属性width,height,但这些属性往往返回空值,因为它们只能返回使用行内style属性定义在元素上的样式 元素的currentStyl ...

  10. ibatis中使用List作为传入参数的使用方法及 CDATA使用

    ibatis中list做回参很简单,resultClass设为list中元素类型,dao层调用: (List)getSqlMapClientTemplate().queryForList(" ...