weixin_33722405 2018-03-26 16:35 采纳率: 0%
浏览 11

表更新和AJAX调用

I'm fairly new to Vue so I'm not sure whether being stupid or not.

I have a table that needs to be updated at a regular interval, so far I've used AJAX to make a call to an API and return the data and that all works great. I'm able to display all my data as required, the issue I'm facing, and this is where my knowledge gets fuzzy, is that on each AJAX call my entire table appears to be getting re-rendered, I thought, or rather hoped, that Vue would only "replace" the data that has changed not the whole table.

Is such a thing possible or am I asking too much?

I've included my code below incase I'm doing something wrong.

App.vue

<template lang="pug">
    .user-agent-overview
        .container
            av-table(:columns="columns" :agentData="agentData") 
</template>

<script>
    import axios from 'axios';

    import avTable from './Table';

    export default {
        data() {
            return {
                agentData: null,
                columns: [
                    'Agent Name',
                    'Status',
                    'First Log in',
                    'Last Log out',
                    'Total On duty',
                    'Total Inbound',
                    'Total Outbound',
                    'Average Talk time',
                    'Total Talk time',
                ],
            };
        },
        created() {
            this.fetchAgentData();
        },
        methods: {
            fetchAgentData() {
                this.error = null;
                this.agentData = null;
                this.loading = true;

                axios
                    .get('/api/v1/ajax-dashboard-aircall/agents')
                    .then(response => {
                        this.agentData = response.data.user_agents;
                    })
                    .catch(error => {
                    });
            },
        },
        components: {
            avTable,
        },
        mounted() {
            // this.$nextTick(() => {
            //  setInterval(function() {
            //      this.fetchAgentData();
            //  }.bind(this), 5000);
           // });
        },
    };
 </script>

Table.vue

<template lang="pug">
    table.table
        thead
            tr
                th(v-for="column in columns") {{ column }}
        tbody
            tr(v-for="(data, dIndex) in agentData" :key="dIndex")
                td(v-for="(item, iIndex) in data" :key="`${iIndex}-${iIndex}`") {{ item }}
</template>

<script>
    import axios from 'axios';

    export default {
        props: ['columns', 'agentData'],
    };
</script>

Thanks David

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
    • ¥15 关于arduino编程toCharArray()函数的使用
    • ¥100 vc++混合CEF采用CLR方式编译报错
    • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
    • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
    • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
    • ¥50 如何openEuler 22.03上安装配置drbd
    • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
    • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
    • ¥15 Windows11, backspace, enter, space键失灵