美文网首页
模板 template 三种写法

模板 template 三种写法

作者: Sharp丶TJ | 来源:发表于2022-05-06 18:42 被阅读0次
一、 Vue 完整版,写在HTML里
//写在html内:
    <div id="xxx">
        {{n}}
        <button @click="'add">
            +1
        </button>
    </div>
//Vue内容:
new Vue({
    el:'#xxx',
    data:{n:0},  //data可以改成函数
    methods:{add(){}}
})
二、Vue完整版,写在选项里
//写在html内:
    <div id="app">
    </div>
//Vue内容:
new Vue({
    template:`
       <div>
        {{n}}
        <button @click="'add">
            +1
        </button>
    </div>`,
    data:{n:0},  //data可以改成函数
    methods:{add(){ this.n +=1 }}
}).$mount('#app')
//div #app 会被替换掉,就是你会发现没有一个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必须为函数
    methods:{add(){this.n += 1}}
}
</script>
<style>这儿写 CSS </style>

然后再另一个地方写:

import Xxx from './xxx.vue'
// Xxx 是一个 options 对象 (Xxx就是script里的对象)
new Vue({
    reder: h=> h(Xxx)
}).$mount('#app')

相关文章

  • 第五节 模板、指令与修饰符

    一、模板的三种写法 第三种里面,不是html,它只是一个标签,用来包裹东...

  • Vue(5)

    1.模板template的三种写法 首先我们要明白template里面不是html语言而是xml语言,标签是需要闭...

  • 模板 template 三种写法

    一、 Vue 完整版,写在HTML里 二、Vue完整版,写在选项里 三、Vue 非完整版,配合 xxx.vue 文...

  • Template 制作模版(13)

    vue的模板有三种写法 一、直接写在选项里的模板 template为何不用双引号或者单引号而是用``,因为我们写模...

  • template模板及三种写法

    一、直接写在选项里的模板 直接在构造器里的template选项后边编写。这种写法比较直观,但是如果模板html代码...

  • 10.组件当中模板字符抽离写法

    模板字符抽离的两种写法: 然后通过id属性绑定

  • Vue模板、指令与修饰符

    模板template三种写法 一. Vue完整版,写在HTML中 二. Vue完整版,写在选项里 三. Vue非完...

  • Vue的模板、指令与修饰符

    1. 模板 template 的三种写法 使用Vue完整版,写在HTML里 使用Vue完整版,写在选项里 这样写,...

  • Vue的模板语法

    模板template的三种写法 第一种:Vue完整版,写在HTML中 第二种:Vue完整版,写在选项里 注意:使用...

  • 力卉编程 | C语言 | 模板类定义

    C++ 中类模板的写法如下: template <类型参数表>class 类模板名{成员函数和成员变量}; 类型参...

网友评论

      本文标题:模板 template 三种写法

      本文链接:https://www.haomeiwen.com/subject/ojkzyrtx.html