如下所示:
<div id="app"> <h1>我是直接寫在構(gòu)造器里的模板1</h1> </div> <template id="demo3"> <h1 style="color:red">我是選項(xiàng)模板3</h1> </template> <script type="x-template" id="demo4"> <h1 style="color:red">我是script標(biāo)簽?zāi)0?</h1> </script> <script> var vm=new Vue({ el:"#app", data:{ message:1 }, //第2種模板 寫在構(gòu)造器里 //template:`<h1 style="color:red">我是選項(xiàng)模板2</h1>` //第3種模板 寫在<template>標(biāo)簽里 //template:'#demo3' //第4種模板 寫在<script type="x-template">標(biāo)簽里 template:'#demo4' }) </script> 推薦第4種。
以上這篇Vue2 模板template的四種寫法總結(jié)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持錯(cuò)新站長站。
新聞熱點(diǎn)
疑難解答
圖片精選