zoukankan      html  css  js  c++  java
  • Vue学习(十二)Dom模版和字符串模版

    Dom模版

    dom模版直接写在dom结构中,例如:

        <div id="box">
            <name></name>
        </div>
        <!-- 父组件模版 -->
        <template id="name">
            <h2>{{msg}} => {{string}}</h2>
            <age :data-msg='msg' :data-string='string'></age>
        </template>
        <!-- 子组件模版 -->
        <template id="age">
            <h2>18</h2>
            <span>{{dataMsg}} => {{dataString}}</span>
        </template>
        <script>
            var vm = new Vue({
                data:{
    
                },
                components:{
                    'name':{
                        data(){
                            return {
                                msg:'我是父组件数据',
                                string:'我是父组件的另外一个数据'
                            }
                        },
                        template:'#name',
                        components:{
                            'age':{
                                props:['dataMsg','dataString'],
                                template:'#age'
                            }
                        }
                    }
                }
            }).$mount('#box');  
        </script>

    字符串模版

    字符串模版写在template属性中,例如:

        <div id="box">
            <aaa></aaa>
        </div>
        <script>
            Vue.component('aaa',{
                template:'<h1 @click="show">{{msg}}</h1>',
                data(){
                    return {
                        msg:'hello vue'
                    }
                },
                methods:{
                    show(){
                        this.msg = 'hello';
                    }
                }
            });
    
            var vm = new Vue({
                data:{
                }
            }).$mount('#box');  
        </script>
  • 相关阅读:
    jquery
    gulp 入门
    bower 教程
    webstrom管理git
    修改页面浏览器自动刷新
    兼容IE低版本
    js之触屏事件篇
    js之日期篇
    设置浏览器默认样式
    Listview四种视图VIEW
  • 原文地址:https://www.cnblogs.com/kunmomo/p/12582436.html
Copyright © 2011-2022 走看看