5-vue-template模板制作

有四种方法制作模板,下边先将前三种制作模板。

注意:模板组件里面第一行只能有一个标签,并且结束标签必须在最后一行,否则结束标签之后的html是无法显示的;

一:直接在构造器中制作模板,构造器模板

    <script>
        new Vue({
            el:'#ele',
            data:{
                message:"",
            },
            template:`
            <h3 style='color:red'>this is the first template</h3>
            `
        })
    </script>

第二种写法,template标签模板,直接在html中进行书写:(相较于第一种模板,第一种模板比较适合比较小的组件)

   <div id='ele'>  
        <h2>template的第二种写法</h2><!--不会显示-->
        <p v-text="message"></p>
    </div>
    <template id='temp2'>
            <h3 style='color:red'>this is the second template</h3>
    </template>

    <script>
        new Vue({
            el:'#ele',
            data:{
                message:"",
            },
            template:"#temp2"
        })
    </script>

第三种写法:script标签template

    <div id='ele'>  
        <h2>template的第三种写法</h2><!--不会显示-->
        <p v-text="message"></p>
    </div>
    <script type="x-template" id='temp3'>
            <h3 style='color:red'>this is the third script template</h3>
    </script>

    <script>
        new Vue({
            el:'#ele',
            data:{
                message:"",
            },
            template:"#temp3"
        })
    </script>

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值