Vue学习—Vue模板的写法

  1. 选项模板:不需要外部构造器,直接渲染到作用域视图中,使用与比较少的内容量可以使用它,可以利用ES6模板字符串``的方式来实现,也可以直接用字符串即"<h1 style="color:red">我是选项模板</h1>",这时template和data、el一样都是Vue实例的一个选项,所以叫做选项模板。
    < body>
    < h1>模板的写法—01</ h1>
    < div id= "app">

    </ div>
    < script>
    var app = new Vue({
    el: "#app",
    data: {

    },
    template: `
    <h1 style="color:red">我是选项模板</h1>
    `
    });
    </ script>
    </ body>
  2. 使用模板标签<template></template>来实现内容的填充,最终通过id或者其他的选择器挂载到template上面
    < body>
    < h1>模板的写法—02</ h1>
    < div id= "app">

    </ div>
    < template id= "demoTpl">
    < h1 style= "color:green;">我是template模板标签</ h1>
    </ template>
    < script>
    var app = new Vue({
    el: "#app",
    data: {

    },
    template: "#demoTpl"
    });
    </ script>
    </ body>
  3. 使用x-template,script标签需要添加text/x-template类型作为标记,并且在在Vue实例中通过id来引用。
    < body>
    < h1>模板的写法—03</ h1>
    < div id= "app"> </ div>
    < script type= "text/x-template" id= "demoXtpl">
    < h1 style= "color:yellow;">我是script标签模板</ h1>
    </ script>
    < script>
    var app = new Vue({
    el: "#app",
    data: {

    },
    template: "#demoXtpl"
    });
    </ script>
    </ body>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值