zoukankan      html  css  js  c++  java
  • vue中全局组件与局部组件的注册,以及动态绑定props值

    <!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>Document</title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <style>
            #app{
                width:100%;
                height:100px;
                background:red;
            }
            .box{
                width:100%;
                height:30px;
                background:yellow;
            }
        </style>
    </head>
    <body>
    <div id="app" @click="onmessage()">
        {{ message }}
        <one-component todo="haha"></one-component>
        <two-component a="enen"></two-component>
        <div class="box" v-for="(item,index) in lala" :key="index">
                <laaaaaa :bbb="item"></laaaaaa>
        </div>
    
    </div>
    <script>
        var objarr=[
            {id:0,text:""},
            {id:1,text:""},
            {id:2,text:""},
            {id:3,text:""},
            {id:4,text:""},
            {id:5,text:""}
        ]
        Vue.component('one-component',{//全局注册
            template:`<div>我是组件{{ todo }}</div>`,
            props:['todo']
        });
        Vue.component('two-component',{//全局注册
            data(){
                return{
                    bb:""
                }
            },
            template:`<div>我是第二个全局组件{{ a }}{{ bb }}</div>`,
            props:["a"]
        });
        var componentA = { //局部注册组件
                template:`<div>我是局部组件{{ hehe }}{{ bbb.id }}{{ bbb.text }}</div>`,
                data(){
                    return{
                        hehe:"我是子组件的值"
                    }
                },
                props:["bbb"]
            }
    var app=new Vue({
        el:"#app",
        components:{
            "laaaaaa":componentA
        },
        data:{
            message:'页面加载于' + new Date().toLocaleString(),
            lala:objarr
        },
        methods: {
            onmessage(){
                this.message='haha'  
            }
        },
        mounted() {
            console.log(this.lala);
        }
    });
    
    
    </script>
    </body>
    </html>
  • 相关阅读:
    LeetCode Find Duplicate File in System
    LeetCode 681. Next Closest Time
    LeetCode 678. Valid Parenthesis String
    LeetCode 616. Add Bold Tag in String
    LeetCode 639. Decode Ways II
    LeetCode 536. Construct Binary Tree from String
    LeetCode 539. Minimum Time Difference
    LeetCode 635. Design Log Storage System
    LeetCode Split Concatenated Strings
    LeetCode 696. Count Binary Substrings
  • 原文地址:https://www.cnblogs.com/fqh123/p/10798163.html
Copyright © 2011-2022 走看看