动态组件 is vue

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .tabbtn{
            background-color: greenyellow;
        }
        /* 交集选择器 */
        .tabbtn.active{
            background-color: hotpink;
        }
    </style>
</head>

<body>
    <div id="app">
        <div>
            <button v-for="(item,index) in btns" :class=['tabbtn',{'active':tab==item+'-com'}] :key="index" @click="btnhandler(item)">{{item}}</button>
            <p :is="tab">qweqwe</p>
        </div>
    </div>
    <script src="../../vue.js"></script>
    <script>

        Vue.component("tab1-com", {template: "<h1>tab1</h1>"});
        Vue.component("tab2-com", {template: "<h1>tab2</h1>"});
        Vue.component("tab3-com", {template: "<h1>tab3</h1>"});
        Vue.component("tab4-com", {template: "<h1>tab4</h1>"});
        // root组件
        const vm = new Vue({
            el: '#app',
            data: {
                tab:'tab1-com',
                btns: ['tab1', 'tab2', 'tab3', 'tab4']
            },
            methods: {
                btnhandler(e) {
                    this.tab = e + '-com';
                }
            },
        });

    </script>
</body>

</html>
上一篇:PartⅠ邮件伪造


下一篇:拷贝分区统计信息