【发布时间】:2018-03-17 18:12:33
【问题描述】:
我想在我的 api 中使用过滤数据的表格上的分页显示。当我将函数放入方法中时,我从 (event-1) 中获取数据,但是当我将项的函数放入计算中时,我得到的不是数据数组而是对象。所以,我的数据无法显示。请问如何获取数据?
<input type="text" class="form-control search ml-4 mb-4" placeholder="search" v-model="filterNameInput" :onChange="filterByName">
<b-table hover responsive="sm" :busy.sync="isBusy" :sort-by.sync="sortBy" :sort-desc.sync="sortDesc" :items="fetchPlaces" :fields="fields" :current-page="currentPage" :per-page="perPage" @row-clicked="rowClickHandler">
<template slot="created" slot-scope="data">
{{ data.item.created | moment().format("YYYY-MM-DD") }}
</template>
<template slot="updated" slot-scope="data">
{{ data.item.updated | moment().format("YYYY-MM-DD") }}
</template>
<template slot="categories" slot-scope="data">
<b-badge v-for="category in data.item.categories" :key="category.id" variant="primary">{{category.name}}</b-badge>
</template>
</b-table>
computed: {
fetchPlaces(ctx) {
let params = '?apikey=apiKey&lng=en&page=' + ctx.currentPage + '&limit=' + ctx.perPage
if (this.sortBy) {
params += '&sort=' + this.sortBy
if (this.sortDesc) {
params += '&dir=DESC'
}
}
if (this.filterStatus !== '' || this.filterNameInput !== '') {
params += '&sort=name&dir=ASC'
if (this.filterStatus !== '') {
params += '&filter[status]=like|' + this.filterStatus
}
console.log(this.filterNameInput)
if (this.filterNameInput !== '') {
params += '&filter[name]=%like%|' + this.filterNameInput
}
}
let promise = this.$http.get(apiUrl + params)
return promise.then((data) => {
let items = data.body.data
this.totalRows = data.body.totalItems
return (items || [])
})
}
}
【问题讨论】: