美文网首页
Vue.js for循环时通过index绑定不同的class

Vue.js for循环时通过index绑定不同的class

作者: TIGER_XXXX | 来源:发表于2017-08-30 17:09 被阅读650次
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script type="text/javascript" src="js/vue.js"></script>
        <style type="text/css">
            .red {
                color: red;
            }
            
            .royalblue {
                color: royalblue;
            }
            
            .aquamarine {
                color: aquamarine;
            }
            
            .chartreuse {
                color: chartreuse;
            }
            
            .crimson {
                color: crimson;
            }
        </style>
    </head>
    <body>
        <div id="test">
            <div v-for="(item,index) in ary" :class="{'red': index == 0,'royalblue': index == 1,'aquamarine': index == 2,'chartreuse': index == 3,'crimson': index == 4}">
                {{item}}
            </div>
        </div>
        <script type="text/javascript">
            new Vue({
                el:'#test',
                data: {
                    ary:[1,2,3,4,5]
                }
            })
        </script>
    </body>
</html>

demo:https://github.com/TigerCui/jsDemo/tree/master/VueForBindClassDemo

相关文章

网友评论

      本文标题:Vue.js for循环时通过index绑定不同的class

      本文链接:https://www.haomeiwen.com/subject/reqxjxtx.html