2

我正在尝试通过调用如下方法删除其中一个站点后更新站点列表getSites()

代码

import http from 'services/http.service';
import logging from 'services/logging.service';

const sites = http('sites', localStorage);

export default {
    getSites({dispatch}) {
        console.log('getSites')
        sites.all().then((response) => {
            dispatch('setSites', response.data.results);
        });
    },
    deleteSite({dispatch}, site) {
        return sites.delete(site).then(() => {
            this.getSites()  // <-------- doesn't works
        });
    },
};

我收到以下错误

删除失败 ReferenceError: getSites 未定义

问题

我应该如何调用获取我的新项目列表?或者我应该在我的组件内做then()吗?

4

1 回答 1

3

我从actions.js中删除了调用,并在我的组件方法中进行了调用:

import actions from 'vuex/actions';

export default{
    // …
    methods: {
        // …
        delete_site(site){
            return this.deleteSite(site).then(response => {
                this.getSites();  // <----------- call from here
            });
        },
    vuex: {
        actions: {
            getSites: actions.getSites,
            deleteSite: actions.deleteSite,
        }
    }
}
于 2016-08-16T16:49:06.263 回答