Vue中使用el-table :data数据更新,但表格不显示

结论:我写的tableData没加reactive
顺便放上尝试过的几个方法:
增加key属性
也是增加key
安装版本更低的element-plus
其他方法

<template>
    <el-table :data="tableData" @change="console.log('changed',tableData);">
        <el-table-column prop="area" label="area"></el-table-column>
        <el-table-column prop="date" label="date"></el-table-column>
        <el-table-column prop="dayForecast" label="dayForecast"></el-table-column>
    </el-table>

</template>

<script setup name="Model" lang="ts">
import axios from 'axios';
import { reactive } from 'vue';
const tableData = reactive([])
async function getData() {
    try {
        const promise1 = await axios({url: 'http://hmajax.itheima.net/api/weather', params: {city: '110100'}})
        tableData.push({
            area: promise1.data.data.area,
            date: promise1.data.data.date,
            dayForecast: promise1.data.data.dayForecast[0].weather,
        })       
        const promise2 = await axios({url: 'http://hmajax.itheima.net/api/weather', params: {city: '310100'}})
        tableData.push({
            area: promise2.data.data.area,
            date: promise2.data.data.date,
            dayForecast: promise2.data.data.dayForecast[0].weather,
        })
        const promise3 = await axios({url: 'http://hmajax.itheima.net/api/weather', params: {city: '440100'}})
        tableData.push({
            area: promise3.data.data.area,
            date: promise3.data.data.date,
            dayForecast: promise3.data.data.dayForecast[0].weather,
        })
        const promise4 = await axios({url: 'http://hmajax.itheima.net/api/weather', params: {city: '440300'}})
        tableData.push({
            area: promise4.data.data.area,
            date: promise4.data.data.date,
            dayForecast: promise4.data.data.dayForecast[0].weather,
        })
        console.log(tableData);
        
    } catch(err) {
        console.dir(err)
    }
    tableData.push({
            area: 'promise1.data.data.area',
            date: 'promise1.data.data.date',
            dayForecast: 'promise1.data.data.dayForecast[0].weather',
        })
}

// //卸载当前版本
// npm uninstall element-ui
// //安装指定版本
// npm i element-ui@2.4.8 -S --legacy-peer-deps
getData()

console.log('aaa',tableData);

</script>
posted @   ayubene  阅读(1555)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示