首页 > 解决方案 > vuesax表格组件数据如何默认降序排序?

问题描述

我正在尝试默认按降序对我的 vuesax 表组件数据进行排序并显示。但是默认情况下它是升序的,当点击表格中的标题 Id 时,它会在 vuesax 中的 sort-key 属性的帮助下以降序排序。任何人都可以帮我将其默认更改为降序。我的脚本在 Vue.Js 中

我的 Vuesax 表格组件代码

 <template slot="thead">
    <vs-th sort-key="id">Id</vs-th>
    <vs-th sort-key="first_name">Name</vs-th>
 </template>

<template slot-scope="{data}">
  <tbody>
    <vs-tr :data="tr" :key="indextr" v-for="(tr, indextr) in data">
       <vs-td>
        <p class="product-name font-medium truncate">{{ tr.id }}</p>
       </vs-td>  
     </vs-tr>
  </tbody>
</template>

标签: sortingvue.js

解决方案


我想你会在这里找到答案:https ://eslint.vuejs.org/rules/sort-keys.html 。

在你的 main.js 文件中,你应该已经导入了 Vuesax。如果没有,您可以执行以下操作并添加相关选项(来自上面的链接):

import Vuesax from 'vuesax'
import 'vuesax/dist/vuesax.css'

Vue.use(Vuesax, {
  // options here
})

推荐阅读