第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

是否可以在導(dǎo)出的模塊中使用 Vuex mapActions

是否可以在導(dǎo)出的模塊中使用 Vuex mapActions

慕勒3428872 2021-06-29 08:41:42
是否可以從導(dǎo)入到組件中的單獨模塊調(diào)用 Vuex mapActions?我正在嘗試標準化 vue.js Web 應(yīng)用程序中的一組函數(shù)。我想將它們導(dǎo)入到每個組件中并傳遞一些值到函數(shù)操作。我正在使用 vuex 來管理狀態(tài)。目前,每個組件每次加載時都會調(diào)用這些函數(shù)(完全相同)。我想將其重構(gòu)為一個模塊,并根據(jù)需要將其導(dǎo)入到每個組件中。此代碼使用 mapActions 作為其功能的一部分。下面是相關(guān)的代碼段:component、module、vuex actionVue 組件://the imported function callif (!this.queued){   timer.updatePage(this.pagination, this.orders);}模塊代碼(advance.js):import { mapActions } from 'vuex';let currentComp = {   name: 'purchase',   date: null,   start: false}const timer = {   ...mapActions(['currentComponent']),   updatePage(pagination, order) {      currentComp.name = 'nextComponent';      this.currentComponent(currentComp);   }}export default timer;Vuex 代碼://in the actions section:currentComponent({        commit    }, comp) {        console.log(comp);        commit('setCurrentComponent', comp);}//in the mutations section:setCurrentComponent: (state, comp) => {        state.currentComponent = comp.name;        return state;    }當組件運行導(dǎo)入的函數(shù)時,我得到:vuex.esm.js?2f62:870 Uncaught TypeError: Cannot read property 'dispatch' of undefined    at Object.mappedAction [as currentComponent] (vuex.esm.js?2f62:870)    at eval (advance.js?935c:37)當我從 this.currentComponent 中刪除 this 時,我得到:advance.js?935c:37 Uncaught ReferenceError: currentComponent is not defined    at eval (advance.js?935c:37)提前感謝您的任何指導(dǎo)。
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 222 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號