模板 template 三種寫法

一、 Vue 完整版,寫在HTML里
//寫在html內(nèi):
    <div id="xxx">
        {{n}}
        <button @click="'add">
            +1
        </button>
    </div>
//Vue內(nèi)容:
new Vue({
    el:'#xxx',
    data:{n:0},  //data可以改成函數(shù)
    methods:{add(){}}
})
二、Vue完整版,寫在選項(xiàng)里
//寫在html內(nèi):
    <div id="app">
    </div>
//Vue內(nèi)容:
new Vue({
    template:`
       <div>
        {{n}}
        <button @click="'add">
            +1
        </button>
    </div>`,
    data:{n:0},  //data可以改成函數(shù)
    methods:{add(){ this.n +=1 }}
}).$mount('#app')
//div #app 會(huì)被替換掉,就是你會(huì)發(fā)現(xiàn)沒有一個(gè)div的id叫app
三、Vue 非完整版,配合 xxx.vue 文件
<template> //這里是XML
    <div>
        {{n}}
        <button @click="add">
            +1
        </button>
    </div>
</template>

<script>
export default {
    data(){return {n:0}},
    //data必須為函數(shù)
    methods:{add(){this.n += 1}}
}
</script>
<style>這兒寫 CSS </style>

然后再另一個(gè)地方寫:

import Xxx from './xxx.vue'
// Xxx 是一個(gè) options 對(duì)象 (Xxx就是script里的對(duì)象)
new Vue({
    reder: h=> h(Xxx)
}).$mount('#app')
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 模板 template 一、 Vue完整版,寫在HTML里 二、 Vue完整版,寫在選項(xiàng)里 三、Vue非完整版,配...
    fanison閱讀 17,305評(píng)論 0 9
  • Vue的模版語法 我們把HTMl模版叫做template。 template的3種寫法 1' Vue完整版,寫在H...
    珍惜時(shí)間小李閱讀 284評(píng)論 0 0
  • 模板template三種寫法 一. Vue完整版,寫在HTML中 二. Vue完整版,寫在選項(xiàng)里 三. Vue非完...
    Marshall3572閱讀 118評(píng)論 0 0
  • 1.template的三種用法 使用Vue完整版,寫在HTML里面 2.使用Vue完整版,寫在選項(xiàng)里面 這樣寫有一...
    雨溪灘閱讀 261評(píng)論 0 2
  • 模板template的三種寫法 第一種:Vue完整版,寫在HTML中 第二種:Vue完整版,寫在選項(xiàng)里 注意:使用...
    我是Msorry閱讀 751評(píng)論 0 0

友情鏈接更多精彩內(nèi)容