• Vue Component 标签


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <div id="app">
            <!-- 调用全局注册的组件 -->
            <button-counter></button-counter>
            <p>----------------------</p>
            <buttonCounter></buttonCounter>
    
            <box1></box1>
            <button-counter></button-counter>
        </div>
        <p>======================</p>
        <div id="root">
            <button-counter></button-counter>
            <box2></box2>
        </div>
        <!-- script标签 -->
    <!--    <script type="text/template" id="button_counter">-->
    <!--        <button @click="count++">点{{count}}次</button>-->
    <!--    </script>-->
    <!--    <script type="text/template" id="div_box2">-->
    <!--        <div style="background-color: red">div_box2<button-counter></button-counter></div>-->
    <!--    </script>-->
        <!-- template标签 -->
        <template id="button_counter">
            <button @click="count++">点{{count}}次</button>
        </template>
        <template id="div_box2">-->
            <div style="background-color: red">div_box2<button-counter></button-counter></div>
        </template>
        <script src="js/vue.3.2.2.js"></script>
        <script>
            //注册一个局部组件
            const Counter={
                data(){
                    return{
                        count: 0
                    }
                },
                template:'#button_counter'
            }
    
            const Box={
                components: {
                    'button-counter':Counter
                },
                template:'#div_box2'
            }
    
            // 1、创建Vue的实例对象
            const app = Vue.createApp({
                data(){//定义数据
                    return {
                        msg:'你好!'
                    }
                }
            });
            const root = Vue.createApp({
                data(){//定义数据
                    return {
                        msg:'你好2!'
                    }
                },
                components:{
                    'button-counter':Counter,
                    'box2':Box
                }
            });
            <!-- 建议使用这种 -->
            app.component('button-counter',{
                data(){
                    return{
                        count: 0
                    }
                },
                template:'<button @click="count++">点击{{count}}次</button>'
            });
            <!-- 这种只有脚手架工程开发时才有效 -->
            app.component('buttonCounter',{
                data(){
                    return{
                        count2: 0
                    }
                },
                template:'<button @click="count2++">点击{{count2}}次</button>'
            });
    
            app.component('box1',{
                template:'<div style="background-color: red">' +
                        'div_box1' +
                        '<button-counter></button-counter>' +
                        '</div>'
            });
    
    
            app.mount('#app');
            root.mount('#root');
        </script>
    </body>
    </html>
  • 相关阅读:
    SRM 551 div2
    HDU_4390 Number Sequence (容斥原理)
    HDU 多校联合第五场
    HDU 多校联合第六场
    POJ 2057 The Lost House (经典树形dp)
    Lucas定理
    HDU 4385 Moving Bricks (状态dp+贪心)
    HDU 多校联合第三场
    当最短路变成二维 _!
    POJ 1848 (一道不错的树形dp)
  • 原文地址:https://www.cnblogs.com/mingforyou/p/15164421.html
Copyright © 2020-2023  润新知