我是javascript和js框架的新手。我有以下vuejs代码片段:

    <div v-for="coefficient in coefficients" class="coefficient">
        <div>
            <span class="name">name:{{coefficient.name}}</span>
            <span class="value">value:{{coefficient.value}}</span>
            <span>---</span>
        </div>
    </div>

输出如下:
name: Ubuntu
value: 1
---
name: MacOS
value: 2
---
name: Windows
value: 3
---

如何排除vuejs的最后一项coefficients

最佳答案

您可以使用computed属性,也可以像这样使用coefficients.slice(0, -1)

new Vue({
  data : {
    coefficients : [
    {name : "a", value : 2},
    {name : "b", value : 3},
    {name : "c", value : 4}]
  },
  el : "#app"
})

<div id="app">
    <div v-for="coefficient in coefficients.slice(0, -1)" class="coefficient">
        <div>
            <span class="name">name:{{coefficient.name}}</span>
            <span class="value">value:{{coefficient.value}}</span>
            <span>---</span>
        </div>
    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>

09-28 03:34