javascript - VueJS 与 bootstrap-vue : one column in table without data

标签 javascript twitter-bootstrap vue.js

我在使用 VueJS 和 bootstrap-vue 表时遇到了一个“小”问题。

“Fahrer”列有数据,但只有当我单击排序箭头或详细信息选项卡时(例如“刷新” View 时),数据才可见。我不知道如何解决这个问题。

Screenshot

<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.dataHTTP.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/

相关文章:

javascript - xmlhttp 请求后未定义 $_POST

javascript - Vuetify : checkbox shows status is checked when it is unchecked, 反之亦然

vue.js - 页头组件 - 无法让 Vuex 更新嵌套子组件上的存储

vue.js - Vue 组件 - 如何处理非 react 性数据?

javascript - nodejs 加密模块与 crypto-js

javascript - 给定一个字符串和一个字符串位置。判断单词是否包裹在 HTML 标签中

javascript - IE8 为不需要的滚动条留出空间

jquery - 在输入时选中隐藏 tr 与某些类,但在奇数行上保留背景颜色

html - Bootstrap 响应式水平 Accordion 面板

javascript - 一些 bootstrap 轮播图像无法在 safari mac 上加载