dashboard/shell/mixins/page-actions.js

37 lines
704 B
JavaScript

const STORE_PAGE_ACTIONS = 'pageActions';
export default {
created() {
this.updatePageActions();
const pageActionHandler = (action) => {
if (this.handlePageAction) {
this.handlePageAction(action);
}
};
this.$store.commit('pageActionHandler', pageActionHandler);
},
beforeUnmount() {
if (this.pageActions) {
this.$store.commit(STORE_PAGE_ACTIONS, []);
}
this.$store.commit('clearPageActionHandler');
},
methods: {
updatePageActions() {
if (this.pageActions) {
this.$store.commit(STORE_PAGE_ACTIONS, this.pageActions);
}
}
},
watch: {
pageActions(a, b) {
this.updatePageActions();
}
}
};