Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vuejs2 vuejs按数组顺序排列表列的最佳实践_Vuejs2 - Fatal编程技术网

Vuejs2 vuejs按数组顺序排列表列的最佳实践

Vuejs2 vuejs按数组顺序排列表列的最佳实践,vuejs2,Vuejs2,我在vuejs上迈出了第一步,遇到了这个问题。我想在表中显示这些数据,使用这段非常简单的代码: <table class="table table-striped table-hover" :class="[hide ? 'thide' : '']"> <thead> <tr> <th v-for="(item, index) in _items[0]">{{fixTheaders(index)}}&

我在vuejs上迈出了第一步,遇到了这个问题。我想在表中显示这些数据,使用这段非常简单的代码:

<table class="table table-striped table-hover" :class="[hide ? 'thide' : '']">
    <thead>
        <tr>
            <th v-for="(item, index) in _items[0]">{{fixTheaders(index)}}</th>
        </tr>
    </thead>
    <tbody>
        <tr v-for="(item, index) in _items">
            <td v-for="field in item">{{item}}</td>
        </tr>
    </tbody>
</table>
因此,在这种情况下,表格将按以下顺序显示数据: 成本|放置|日期|设备
但我希望顺序是:日期|设备|成本|位置
我有一种感觉,最好的方法是使用数组:

filters = ['date,'device','cost','placement'] 
并使用它,但我找不到vuejs的方法来处理它。 那么,在vuejs中,按照我在数组中设置的顺序在表中显示数据的最佳做法是什么呢


值得一提的是,初始化时,顺序是在服务器上确定的,从这边修复它不是一个选项

就我个人而言,我只需要硬编码标题,并在tbody中获得正确的值

<tbody>
    <tr v-for="(item, index) in _items">
        <td>{{item.date}}</td>
        <td>{{item.device}}</td>
        <td>{{item.cost}}</td>
        <td>{{item.placement}}</td>
    </tr>
</tbody>

{{item.date}
{{item.device}
{{item.cost}
{{item.placement}

当然,除非您需要对它们执行更多操作,否则我会选择按所需顺序包含列键的属性:-)

抱歉-刚刚注意到您从服务器获得了顺序(为什么,我想知道,但这不是您的问题)-在这种情况下,无论如何,只需将顺序添加到数组中即可。甚至更好-如果订单来自您的服务器,为什么您不能在将数据发送到客户端之前在服务器上订购数据?
<tbody>
    <tr v-for="(item, index) in _items">
        <td>{{item.date}}</td>
        <td>{{item.device}}</td>
        <td>{{item.cost}}</td>
        <td>{{item.placement}}</td>
    </tr>
</tbody>