我在使用 VueJS 和 bootstrap-vue 表时遇到了一个“小”问题。
“Fahrer”列有数据,但只有当我单击排序箭头或详细信息选项卡时(例如“刷新” View 时),数据才可见。我不知道如何解决这个问题。
<template>
<div style="width: 80vw;">
<b-card no-body>
<b-tabs card v-model="tabIndex" >
<b-tab title="Übersicht">
<b-table responsive flex style="width: 100%; max-height: 70vh;" @click="tableClick" striped hover :items="tours" :fields="fields" :current-page="currentPage" :per-page="perPage" >
<template slot="actions" slot-scope="row">
<b-button size="sm" @click.stop="tableClick(row.item)" class="mr-1">
Info
</b-button>
</template>
</b-table>
<div class="pagination-div">
<b-pagination :total-rows="totalRows" :per-page="perPage" v-model="currentPage"/>
</div>
</b-tab>
<b-tab title="Details">
//...
</b-tab>
</b-tabs>
</b-card>
</div>
</template>
<script>
import { HTTP } from '@/axioscommon'
import Minimap from '@/components/Elements/Minimap'
export default {
name: 'tours',
components: {
Minimap
},
data () {
return {
//...,
tours: [{
id: '',
kfz: '',
loadno: '',
driver: '',
contracts: [''],
device: ''
}],
fields: [
{
key: 'loadno',
label: 'Ladeschein',
sortable: true
},
{
key: 'tourname',
label: 'Tourname',
sortable: true
},
{
key: 'driver',
label: 'Fahrer',
sortable: true
},
{
key: 'kfz',
label: 'Kennzeichen',
sortable: true
},
{
key: 'actions',
label: '',
sortable: false
}
]
}
},
methods: {
tableClick (row, index) {
//...
},
fetchInitialData () {
HTTP.get('tour')
.then(response => {
this.totalRows = response.data.length
for (let index = 0; index < response.data.length; index++) {
HTTP.get('driver/' + response.data[index]['driverID'])
.then(drv => {
response.data[index].driver = drv.data['firstname'] + ' ' + drv.data['lastname']
})
}
console.log(response.data)
this.tours = response.data
})
}
},
mounted () {
this.fetchInitialData()
}
}
</script>
<style scoped>
.fade.show {opacity: 1}
</style>
我已经用几个浏览器测试过它 - 但没有成功。我在用着: 版本2.5.2 Bootstrap 4.0.0 Bootstrap-Vue 2.0.0 Webpack 2.6.1
最佳答案
this.tours = response.data
在 HTTP.get('driver/')
完成之前设置。而且您只更改对象属性,因此 Vue 无法检测到更改。
您可以通过深度复制数组来解决此问题
fetchInitialData () {
HTTP.get('tour')
.then(response => {
this.totalRows = response.data.length
for (let index = 0; index < response.data.length; index++) {
HTTP.get('driver/' + response.data[index]['driverID'])
.then(drv => {
const driverName = drv.data['firstname'] + ' ' + drv.data['lastname']
const tours = [...this.tours]
// or const tours = JSON.parse(JSON.stringify(this.tours))
tours[index].driver = driverName
this.tours = tours
})
}
console.log(response.data)
this.tours = response.data
})
}
关于javascript - VueJS 与 bootstrap-vue : one column in table without data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50971547/