Vue-template

temmplate 模板使用
1 这两种写法几乎一致 只是是否简写
 const demo ={
        template:'<div> <h2>hello </h2></div>   '
    }
    const app = Vue.createApp(demo);
    app.mount("#app")
 Vue.createApp({
        template:`<h2>hello vue3</h2>`
    }).mount('#app')
2定义 script的 type为 x-template 使用起来和 上门的1差不多
 <script type="x-template" id="tem">
        <div>
            <h2>{{msg}}</h2>
            <h2>{{counter}}</h2>
            <button @click='add'>+1</button>
            <button @click='jian'>-1</button>
        </div>
    </script>

在template中 通过 id获取

template:'#tem',
3.最好用的方法 在 body中 直接使用 template 同样是 在template中 通过 id获取
<body>
    <div id="app">
    </div>
    <template id="tem">
        <div>
            <h2>{{msg}}</h2>
            <h2>{{counter}}</h2>
            <button @click='add'>+1</button>
            <button @click='jian'>-1</button>
            <button @click="btnClick">button</button>
            <button @click="btn2Click">2</button>
        </div>
    </template>
</body>
在浏览器中 不会 解析 template中的内容 直接放在body中使用 会有代码提示符 出现 template作为模板 在一些块级的显示隐藏或渲染是 把 div换为template 减少dom节点 的渲染 也避免污染
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值