I've got a "little" problem with VueJS and a bootstrap-vue table.
The column "Fahrer" has data, but the data is only visible, when I click on the sorting-arrows or the details-tab (eg when "refreshing" the view). I have no idea how to solve this problem.
<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>
I have tested it with several browsers - without success. I'm using: Vue 2.5.2 Bootstrap 4.0.0 Bootstrap-Vue 2.0.0 Webpack 2.6.1
this.tours = response.data
is set before HTTP.get('driver/')
is finish. And you only change object properties, so Vue can't detect the change. You can fix this by deep copy the array
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
})
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.