vue--elementui表格--axios(get)---调数据渲染页面

html代码
是elementUI的table

       <div style="margin: 20px 0;">
            <el-table
                    :data="tableData"
                    border
                    style="width: 100%"
                    >
                <el-table-column
                        fixed
                        prop="id"
                        label="序号"
                        width="150">
                </el-table-column>
                <el-table-column
                        prop="xingMing"
                        label="姓名"
                        width="120">
                </el-table-column>
                <el-table-column
                        prop="shouJiHao"
                        label="手机号"
                        width="120">
                </el-table-column>
                <el-table-column
                        prop="buMen"
                        label="部门"
                        width="120">
                </el-table-column>
                <el-table-column
                        prop="zhangHao"
                        label="账号"
                        width="300">
                </el-table-column>
                <el-table-column
                        prop="miMa"
                        label="密码"
                        width="120">
                </el-table-column>
                <el-table-column
                        flot="left"
                        label="操作"
                        width="180">
                    <template slot-scope="scope">
                        <el-button @click="handleClick(scope.row)" type="text" size="small">详情</el-button>
                        <el-button type="text" size="small">删除</el-button>
                        <el-button type="text" size="small">修改</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>

js代码
首先定义一个空数组
然后再methods里定义个函数,axios请求数据

new Vue({
    el:'#main',
    data:{
            tableData: []
    },
    //mounted() {
    //    this.getTabelInfo();
    //},
    methods: {
        getTabelInfo(){
            let _that = this;
            axios.get('url/', {
            }).then(function(response){
                console.log(response.data.object.list);//请求正确时执行的代码
                console.log(_that.tableData)//先打印一下空数组
                _that.tableData=response.data.object.list//将后台传递的数组赋值给定义的空数组
                console.log(_that.tableData)//检查一下数组内是否有数据
            }).catch(function(response){
                console.log(response);//发生错误时执行的代码
            })
        },
    },


})

最后在mounted调用定义的函数

mounted() {
        this.getTabelInfo();
    },

展示渲染好的表格
在这里插入图片描述

这样就成功啦!!!

  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
Vue Seamless Scroll 是一款用于 Vue.js 的滚动组件,它可以帮助你在列表滚动到底部时无缝加载更多数据。然而,有时候可能会遇到不会自动循环数据的问题,这可能是由于以下几个原因: 1. **配置错误**:确保你在使用该插件时正确设置了 `seamless` 或 `infiniteScroll` 选项,并且触发加载的阈值(如 `distanceToTriggerInfiniteScroll`)设置合理。 ```javascript <vue-seamless-scroll :data="items" :infinite-scroll="loadMoreItems"> <!-- 内容 --> </vue-seamless-scroll> ``` 2. **`loadMoreItems` 函数**:检查 `loadMoreItems` 函数是否能正常获取新的数据并更新数据源 `items`,确保每次加载后的数据都被添加到了现有数组的末尾。 ```javascript methods: { loadMoreItems() { this.$axios.get('api/data') .then(response => { this.items = [...this.items, ...response.data]; }) .catch(error => console.error('Error loading more items:', error)); } } ``` 3. **数据同步问题**:如果数据是异步加载或者需要处理的状态管理,确保数据在正确的时间点已加载完成并且已经被 Vue 渲染。 4. **组件状态管理**:如果你使用了 Vuex 等状态管理库,确保在 actions 和 mutations 中的数据操作已经正确地影响到了组件的 state。 如果以上步骤都确认无误,但是问题仍然存在,可以尝试更新组件版本或者查阅官方文档以及社区讨论,寻找解决方案或查找是否有已知的 bug。同时,
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值