重新加载 vue-tables-2 (Vuex) 的数据 [英] Reload Data of vue-tables-2 (Vuex)

查看:97
本文介绍了重新加载 vue-tables-2 (Vuex) 的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模块:https://github.com/matfish2/vue-tables-2

我正在创建一个 CRUD 应用程序.如何在 vue-tables-2 中重新加载通过 Ajax 调用获取的数据?我想在我的应用程序中的某处执行更新语句后重新加载表.

I'm creating a CRUD app. How can I reload the data fetched via Ajax call in vue-tables-2? I wanted to reload the table after an update statement is executed somewhere in my app.

Vue-tables 在我的设置中使用了 vuex.

Vue-tables is using vuex in my setup.

<v-server-table 
    name="UserAdmin" url="admin/master/?format=json" :columns="columns" :options="options">
</v-server-table>

为数据属性添加了表格的 Javascript 代码.

Added Javascript code of the table for data properties.

export default {
    data() {
        return {
            columns: ['ID','NAME', 'POSITION', 'APPLICATIONS','DESCRIPTION','STATUS','ENCODED_BY'],
            options: {
                responseAdapter: (resp) => {
                    resp = resp.map(item => ({ 
                        ID: item.ID,
                        FK_ID: item.FK_ID,
                        NAME: `${item.FIRSTNAME} ${item.LASTNAME}`, 
                        POSITION: item.POSITION,
                        APPLICATIONS: item.APPLICATIONS,
                        DESCRIPTION: item.DESCRIPTION,
                        STATUS: item.STATUS,
                        ENCODED_BY: item.ENCODED_BY,
                        TOTAL: item.TOTAL
                    }));
                    let count;
                    if(resp[0] != null) {
                        count = resp[0]['TOTAL']
                    }
                    else {
                        count = 0
                    }
                    return { 
                        data: resp,
                        count: count
                    }
                },
                headings: {
                    'ID': <span># &nbsp;</span>,
                    'NAME':'Name', 
                    'POSITION':'Position', 
                    'APPLICATIONS':'Applications', 
                    'DESCRIPTION':'Description', 
                    'STATUS': 'Status', 
                    'ENCODED_BY':'Encoded By', 
                    'edit': 'Options'
                },
                columnsClasses: {
                        ID: 'col-md-1',
                        NAME:'col-md-2 pointer',
                        POSITION: 'col-md-2',
                        APPLICATIONS: 'col-md-2',
                        DESCRIPTION: 'col-md-2',
                        STATUS: 'col-md-1',
                        ENCODED_BY: 'col-md-2',
                },
                templates: {
                    NAME: (h, row) => {
                        return <a on-click={ () => this.setUpdateID(row) }>{row.NAME}</a>
                },
                APPLICATIONS: (h,row) => {
                    return (<ul>{JSON.parse(row.APPLICATIONS).map((val)=>(<li>{val}</li>))}</ul>);
                },
                STATUS: (h, row) => {
                    if(row.STATUS == 1) {
                        return <span class="label label-success">Active</span>
                    }
                    else if(row.STATUS == 0) {
                        return <span class="label label-danger">Inactive</span>
                    }
                }
                },
            },
        }
    },
    methods: {
        setUpdateID: function(row) {
            this.$store.commit('SET_UPDATE_ID', row.FK_ID);
        }
    }
}

推荐答案

如文档所述,您应该使用 refresh 方法.您可以在此处阅读refs

As documented you should use the refresh method. You can read about refs here

<v-server-table ref="table"
    name="UserAdmin" url="admin/master/?format=json" :columns="columns" :options="options">
</v-server-table>

Javascript:

Javascript:

methods:{
   onUpdate() {
     this.$refs.table.refresh();
    }
}

这篇关于重新加载 vue-tables-2 (Vuex) 的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆