如何从 Vuex/Vues 中的动作中调用另一个动作?
How to call another action from actions in Vuex/Vues?
我正在尝试更新 站点列表 ,然后通过调用 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
});
},
};
我收到以下错误
deletion failed ReferenceError: getSites is not defined
问题
我应该如何调用获取我的新项目列表?或者我应该在我的组件内完成 then()
?
我从 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,
}
}
}
我正在尝试更新 站点列表 ,然后通过调用 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
});
},
};
我收到以下错误
deletion failed ReferenceError: getSites is not defined
问题
我应该如何调用获取我的新项目列表?或者我应该在我的组件内完成 then()
?
我从 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,
}
}
}