美文网首页
04-Vue-template的两种写法

04-Vue-template的两种写法

作者: 木易先生灬 | 来源:发表于2018-09-22 23:13 被阅读0次

    template的两种写法

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title></title>
        <!-- vue.min.js -->
        <script src="./js/vue.min.js"></script>
    </head>
    <body>
    
        <!-- dom -->
        <div id="app">
        <my-component1></my-component1>
        </div>
    
        <!-- 模板写法1 -->
        <template id="tmpl1">
            <h1>我是模板写法1</h1>
        </template>
    
        <!-- 模板写法2 -->
        <script type="text/html" id="tmpl2">
            <h1>我是模板写法2</h1>
        </script>
        
        <script>
        
            // 创建vue实例
            new Vue({
                el: '#app',
                data: {},
                components: {    // 注册局部组件
                    'my-component1': {
                        template: `#tmpl2`
                    }
                }
            })
            
        </script>
    
    </body>
    </html>

    相关文章

      网友评论

          本文标题:04-Vue-template的两种写法

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