×

VUE开发小应用:TAB切换应用

作者:jiang2021.09.13来源:Web前端之家浏览:3349评论:0
关键词:vuejs

VUE开发小应用:TAP切换应用。实例走起。

HTML:

<div id="tab">
            <ul>
                <li v-on:mouseover="change(index)" :class="[currentindex==index?'active':'']":key="item.id"v-for="(item,index) in list">{{item.text}}</li>
            </ul>
            <div :class="[currentindex==index?'current':'']" v-for="(item,index) in list">
                <img :key="item.id" v-bind:src="item.imgsrc"/>
            </div>
</div>

JS:

<script type="text/javascript">
    var vm = new Vue({
        el:'#tab',
        data:{
            currentindex:'0',//当前选项卡的索引
             list:[{
                id:'1',
                text:'apple',
                imgsrc:'imgs/1.jpg'
            },{
                id:'2',
                text:'orange',
                imgsrc:'imgs/2.jpg'
            },{
                id:'3',
                text:'lemon',
                imgsrc:'imgs/3.jpg'
            }]
            },
            methods:{
                change:function(index){
                this.currentindex=index;
                     }
            }
            });
</script>

大家可以试试吧。

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/vuejs20210913a1.html

网友评论文明上网理性发言 已有0人参与

发表评论: