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 使用C#,asp.net读取Excel文件并保存到Oracle数据库
    • ¥15 C# datagridview 单元格显示进度及值
    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配