vue循环渲染不同样式

html

<div id="wrap" class="box">
    <div v-for="(list,index) in navLists" class="nav" :class="{ red:changeRed == index}" @click="reds(index)">{{list.text}}</div>
</div>

css

*{
                padding: 0;margin: 0;
            }
            .box{
                height: 40px;
                background: cyan;
            }
            .nav{
                line-height: 40px;
                display: inline-block;
                margin-left: 100px;
                cursor: pointer;
            }
            .red{
                color: red;
            }

js

/前提是必须引入vuejs哦!
var vm = new Vue({
            el:"#wrap",
            data:{
                navLists:[
                    {
                        "text":"首页"                     
                    },
                    {
                        "text":"组件"                     
                    },
                    {
                        "text":"API"                        
                    },
                    {
                        "text":"我们"                     
                    }
                ],
                changeRed:0
            },
            methods:{
                reds:function(index){
                    this.changeRed = index;
                }
            }
        });
发布了33 篇原创文章 · 获赞 0 · 访问量 3179

猜你喜欢

转载自blog.csdn.net/YYY1920/article/details/103242411