VUE style 绑定

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <script src="vue.js"></script> -->
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <ul>
            <li :style="{color:colors[i]}" v-for="(item,i) in list" @click="show(item,i)">选项{{item}}</li>
        </ul>
    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                list: [1, 2, 3, 4, 5],
                colors: ['balck', 'green', 'yellow', 'purple', 'blue']
            },
            methods: {
                show: function (item, i) {
                    this.$set(this.colors, i, 'red')
                }
            }
        })
    </script>
</body>

</html>

 

posted on 2020-02-21 17:43  覃隆强  阅读(502)  评论(0编辑  收藏  举报