You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VueJS祖孙组件传值问题:Axios请求数据无法传递至Quasar表格

解决Quasar封装q-table组件异步数据不渲染的问题

我之前踩过一模一样的坑!把Quasar的q-table封装成复用组件后,静态数据跑的好好的,一用Axios异步拉数据就歇菜,大概率是响应式处理或者props传递/绑定的问题,咱们一步步来解决:

第一步:确保父组件(EmployeeComponent)的数据是响应式的

异步数据加载后不更新子组件,最常见的原因就是父组件的tableTds没被Vue监听。你得保证它是Vue的响应式数据:

Vue2 示例

<template>
  <table-component :tableThs="tableThs" :tableTds="tableTds" :is-loading="isLoading"></table-component>
</template>

<script>
import axios from 'axios'
import TableComponent from './TableComponent.vue'

export default {
  components: { TableComponent },
  data() {
    return {
      tableThs: [
        // 你的列配置,比如:
        { name: 'name', label: '姓名', field: 'name' },
        { name: 'position', label: '职位', field: 'position' }
      ],
      tableTds: [], // 初始化为空数组,必须在data里声明才是响应式
      isLoading: false
    }
  },
  mounted() {
    this.fetchEmployeeData()
  },
  methods: {
    async fetchEmployeeData() {
      this.isLoading = true
      try {
        const res = await axios.get('/api/employees')
        // 直接赋值即可,Vue会监听数组的替换
        this.tableTds = res.data
      } catch (err) {
        console.error('加载员工数据失败:', err)
      } finally {
        this.isLoading = false
      }
    }
  }
}
</script>

Vue3 示例(

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:05:42