04-Vue-template的两种写法

2018-09-22  本文已影响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>
上一篇下一篇

猜你喜欢

热点阅读