22_template模板外置

2018-02-10  本文已影响0人  CHENPEIHUANG
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <div id="app">
            <my-component></my-component>
        </div>
        <script src="js/vue.js"></script>
        <script type="x-template" id="myTmpl">
            <div>
                <h1>标题--{{title}}</h1>
                <h2>内容--{{content}}</h2>
            </div>
        </script>
        <script>
            var vm = new Vue({
                el:"#app",
                components:{
                    'my-component':{
                        //模板使用x-template引入
                        template:"#myTmpl",
                        data(){
                            return {
                                title:"标题插值成功",
                                content:"内容插值成功"
                            }
                        }
                    }
                }
            })
        </script>
    </body>
</html>

上一篇 下一篇

猜你喜欢

热点阅读