美文网首页
Vue简体tab切换

Vue简体tab切换

作者: 苹果咏 | 来源:发表于2020-03-10 18:40 被阅读0次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        button.active{
            color:red;
        }
    </style>
</head>
<body>
    <div id="app">
        <div>
            <div class="button_tab">
                <button data-type="goods" :class="{active:index===tabIndex}" 
                    v-for="(item,index) in detailTab"
                    @click="changeTab(index)"
                    >
                    {{ item }}</button>
            </div>
            <div class="content">
                <div v-show="tabIndex==0" class="list1">
                    1
                </div>
                <div v-show="tabIndex==1" class="list2">
                    2
                </div>
            </div>
        </div>
        
    </div>
</body>
</html>
<script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
<script>
    let detailTab = ['商品详情', '本店成交']

    new Vue({
        el: '#app',
        data: {
            tabIndex: 0,
            detailTab
        },
        methods: {
            changeTab(index){
                this.tabIndex = index
                if(index === 1){
                    this.getDeal()// 点击再获取数据
                }
            },
            getDeal(){
                axios.get(url.deal, {id})
                .then(res => {
                    this.dealLists = res.data.data.lists
                })
            }
        },
    })
</script>
图片.png

相关文章