https://github.com/vuejs/vue/...

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
    <div id="app">

        <ul class="list-group">
            <li class="list-group-item" :class="{ 'active': active(item) }" v-for="item in items" track-by="id" @click="toggle(item)">{{item.id}}</li>
        </ul>

    </div>

    <script src="http://cdn.bootcss.com/vue/1.0.17/vue.js"></script>
    
    <script>
        'use strict';

        new Vue({
            el: '#app',
            data: function () {
                return {
                    items: [
                        { id: 1 },
                        { id: 2 },
                        { id: 3 },
                        { id: 4 },
                    ],
                    selected: [],
                }
            },
            methods: {
                toggle: function (item) {
                    var index = this.selected.indexOf(item)

                    if (index === -1) {
                        this.selected.push(item)
                    }
                    else {
                        this.selected.splice(index, 1)
                    }
                },
                active: function (item) {
                    return this.selected.some(t => t === item)
                },
            },
        })
    </script>
</body>
</html>

Chobits
7.4k 声望171 粉丝

保卫骡博 Chobits#3780


下一篇 »
asp.net log4net