【发布时间】:2021-11-27 07:52:21
【问题描述】:
我的尝试是尝试对方法中的数据结果进行排序,但后来我想在表头中实现一个按钮,但我什至无法使用 a、b 解决方案的排序部分来自rows = [] 的数据。我可以使用 vuetify 表,但我想了解如何手动操作...
简单来说,我想按这个行数组 Amount_Raised_Millions 排序
<template>
<div class="container-fluid">
<div class="row mb-10">
<main role="main" class="col-md-12 ml-sm-auto col-lg-12 pt-3 px-4">
<div class=" pb-2 ma-3 ">
<h2 class="center">Funding</h2>
<v-divider></v-divider>
</div>
<div class=" table-responsive">
<table class="table table-striped mb-0">
<thead>
<tr>
<th>Name</th>
<th>Funding Date</th>
<th>Amount Raised</th>
<th>Round</th>
<th>Total Raised</th>
<th>Founder</th>
<th>Est.</th>
<th>Location</th>
<th>Lead Investor</th>
<th class="d-none">Employees</th>
</tr>
</thead>
<span class="table-span">
<v-row class="center mt-15" v-if="loading">
<v-col
cols="12"
>
<v-progress-circular
:size="150"
color="blue"
indeterminate
> Loading...
</v-progress-circular>
</v-col>
</v-row>
<tbody >
<Row v-bind:key="row.id" v-for="row in rows" v-bind:row="row" />
</tbody>
</span>
</table>
</div>
</main>
</div>
</div>
</template>
<script>
import Row from '@/components/Row.vue';
const { GoogleSpreadsheet } = require('google-spreadsheet');
const creds = require('@/client_secret.json');
export default {
name: "Sheet",
components: {
Row
},
props: ["sheet"],
data() {
return {
rows: [],
loading: true,
}
},
methods:{
async accessSpreadSheet() {
const doc = new GoogleSpreadsheet(process.env.VUE_APP_API_KEY);
await doc.useServiceAccountAuth(creds);
await doc.loadInfo();
const sheet = doc.sheetsByIndex[0];
const rows = await sheet.getRows({
offset: 1
})
this.rows = rows.sort((a,b)=>a.Name-b.Name);
this.loading = false;
//console.log(rows)
}
},
created() {
this.accessSpreadSheet();
// testing console.log(process.env.VUE_APP_API_KEY)
},
//computed() {
//return this.rows.sort((a,b)=>a.row.Name-b.row.Name);
//}
}
</script>
【问题讨论】: