我是靠谱客的博主 老实大地,这篇文章主要介绍vue中template的三种写法,现在分享给大家,希望可以做个参考。

第一种(使用模板字符串)早期字符串拼接年代

 <div id="app"></div>
 new Vue({
            el: "#app",
            template: '<div>
                            <h1>{{message}}</h1>
                        <div>',
            data: {
                message: '字符串拼接'
            }
        })


####第二种(使用script元素)HTML5标准之前的写法 ```

<script type="text/x-template" id="tem">
    <div>
        <h1>{{message}}</h1>
    </div>
</script>
 

new Vue({
el: "#app",
template: '#tem',
data: {
message: 'HTML5标准之前的写法,存在一定弊端(可自行google)
之后HTML5发布的template元素弥补了此方式的缺点'
}
})


<br>

####第三种(使用template元素)HTML5标准之后的写法【第二种的升级版】
<template id="tem">
    <div>
        <h1>{{message}}</h1>
    </div>
</template>
 

new Vue({
el: "#app",
template: '#tem',
data: {
message: 'HTML5中的template标签 ,注意:
template是HTML5中的标签,
不是自定义标签,
也不是Vue中的组件
MDN-docs:https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/template '
}
})

 

最后

以上就是老实大地最近收集整理的关于vue中template的三种写法的全部内容,更多相关vue中template内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(135)

评论列表共有 0 条评论

立即
投稿
返回
顶部