ITPub博客

首页 > 应用开发 > > vue实现选项卡报错

vue实现选项卡报错

作者:minger 时间:2019-09-04 12:03:17 0 删除 编辑

刚学vue,想用vue实现一个选项卡功能,可是却报错,网上查找也没查找到什么原因。麻烦大家能够帮忙指点指点,谢谢!

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>选项卡</title>
<style>

</style>



<style>
    li {
        list-style: none;
        float: left;
        margin-right: 20px;
    }
    
    .div-content-wrap {
        width: 200px;
        height: 100px;
    }
    
    .div-content {
        width: 200px;
        height: 100%;
    }
    
    .active {
        color: #ff0000;
    }
</style>

</head>

<body>

<div id="app">
    <ul class="clearfix">
        <li v-for="(list,index) in lists" :key="index" v-on:click="showCurrentcontent(index)" v-bind:class="{active: isActive == index}">
            {{list}}
        </li>
    </ul>
    <div class="div-content-wrap">
        <component is="currentTabContent"></component>
    </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<script>
    var lists = [
        "选项卡1",
        "选项卡2",
        "选项卡3"
    ];
    var content1 = {
        template: "<div class='div-content'>选项卡1</div>"
    };
    var content2 = {
        template: "<div class='div-content'>选项卡2</div>"
    };
    var content3 = {
        template: "<div class='div-content'>选项卡3</div>"
    };
    new Vue({
        el: "#app",
        data: {
            index: 0,
            lists: lists,
            isActive: 0,
            arr: [content1, content2, content3]
        },
        components: {
            "content1": content1,
            "content2": content2,
            "content3": content3
        },
        computed: {
            currentTabContent: function() {
                return this.arr[this.isActive]
            }
        },
        method: {
            showCurrentcontent: function(index) {
                console.log(index);
                this.isActive = index;
            }
        }
    })
</script>


</body>

</html>

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1427/viewspace-3120318/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    121
  • 访问量
    689