VUE中template的三种写法

VUE中template的三种写法

一、直接写在构造器中

<!-- 第一种写法:直接写在构造器里 -->
    <div id ="app1"> </div>
    <script>
        var vm1 = new Vue({
           el: '#app1',
           data: {},
           methods: {},
           template:`<h3>在构造器中的文字</h3>`
        });
       </script>

二、写在HTML自带的<template>标签中

<!-- 第二种写法:写在HTML自带的标签里 -->
   <div id ="app2">
       <template id="item1">
        <h3>Template标签的文字</h3>
       </template>
    </div>
    <script>
        var vm2 = new Vue({
           el: '#app2',
           data: {},
           methods: {}, 
           template:'#item1'
        });
       </script>

三、写在<script>标签中

<!-- 第三种写法:写在script标签里 -->
   <div id ="app3">
       
     </div>
   <script type="x-template" id="item3">
        <h3>写在script的文字</h3>
   </script>
    <script>
     let vm3 = new Vue({
        el: '#app3',
        data: {},
        methods: {},
       
        template:'#item3'
     });
    </script>

 

posted @ 2021-10-15 15:26  码农阿亮  阅读(2374)  评论(0编辑  收藏  举报