小编nol*_*and的帖子

使用Vue JS在v-repeat中定位最后一项

我有一个从json中提取的项目的v重复列表.

我想定位列表中的最后一项来更改其类.

我该怎么做?我的代码如下......

HTML

<div id="app">
...
            <ul id="menu">
                <li v-repeat="items">
                    <i class="material-icons">{{ icon }}</i>
                    {{ name }}
                </li>
            </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

JS

var apiUrl = 'inc/menu.json.php'

new Vue({
    el: '#app',
    data: {
        active: true,
        items: []
    },
    ready: function(){
        this.fetchData()
    },
    methods: {
        toggle: function () {
            this.active = !this.active;
        },
        fetchData: function(){
            var xhr = new XMLHttpRequest(),
                self = this
            xhr.open('GET', apiUrl)
            xhr.onload = function () {
                self.items = JSON.parse(xhr.responseText)
            }
            xhr.send()
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

javascript vue.js

4
推荐指数
2
解决办法
6796
查看次数

标签 统计

javascript ×1

vue.js ×1