Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.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
Javascript VUEJS中的排序表_Javascript_Html_Vue.js - Fatal编程技术网

Javascript VUEJS中的排序表

Javascript VUEJS中的排序表,javascript,html,vue.js,Javascript,Html,Vue.js,我是vue.js的新手,所以我无法按支出金额对表进行排序。我想有一个机会来排序,最高或最低的广告费用。 我编写了以下代码,以尝试对我的表进行排序。但是,此代码不起作用 <template> <div class="row"> <h1> Campaign performance </h1> <table class="table table-sortable">

我是vue.js的新手,所以我无法按支出金额对表进行排序。我想有一个机会来排序,最高或最低的广告费用。 我编写了以下代码,以尝试对我的表进行排序。但是,此代码不起作用

<template>
    <div class="row">
        <h1> Campaign performance </h1>
        <table class="table table-sortable">
            <thead>
                <tr>
                    <th scope="col">Client</th>
                    <th scope="col">Mediachannel</th>
                    <th scope="col">Campaign</th>
                    <th scope="col">Spend</th>
                </tr>
            </thead>
        <tbody>
            <tr v-for="(campaign, name) in campaignPerformance" :key="campaign.campaignID">
                 <td>{{campaign.client}}</td>
                 <td>{{campaign.mediaChannel}}</td>
                 <td>{{campaign.campaign}}</td>
                 <td>{{campaign.spend}}</td>
            </tr>
        </tbody>
        </table>
</div></template>
<script>
import axios from'axios';
export default {
  data() {
   return {
    };
  },
props: ['campaignPerformance'],
components: {},
methods: {
 sortTable() {
  this.campaign.spend.sort((a,b) => a.rating < b.rating ? 1 : -1); //Just tried to sort by highest spend 
  },
},
computed: {
 filteredCampaigns() {
  let filter = new RegExp(this.filterText, 'i')
  return this.campaign.spend.filter(el => el.campaign.campaign.match(filter))
}
},
created() {},
};
</script>

竞选业绩
客户
媒体频道
运动
花费
{{campaign.client}}
{{campaign.mediaChannel}
{{campaign.campaign}
{{campaign.spend}
从“axios”导入axios;
导出默认值{
数据(){
返回{
};
},
道具:['campaignPerformance'],
组件:{},
方法:{
排序表(){
this.campaign.expense.sort((a,b)=>a.ratingel.campaign.campaign.match(filter))
}
},
已创建(){},
};

任何帮助都将被感谢,以使此代码工作,或对其他方式排序表的建议

就排序函数而言,它取决于您希望以何种方式对其进行排序

如果a小于b,并且希望它们在列表中的顺序相同,则输出-1而不是1

看这个例子

this.campaign.spend.sort((a, b) => {
    if (a.rating === b.rating)  return 0
    if (a.rating < b.rating) return -1
    if (a.rating > b.rating) return 1
})
this.campaign.spend.sort((a,b)=>{
如果(a.rating==b.rating)返回0
如果(a评级b评级)返回1
})

控制台中出现错误?