在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vuex 中數(shù)據(jù)請求后返回的結(jié)果怎么傳遞到組件中去?

vuex 中數(shù)據(jù)請求后返回的結(jié)果怎么傳遞到組件中去?

1.現(xiàn)在我在vuex的actions中用axios發(fā)送請求后臺得到了數(shù)據(jù)。
2.要處理這個數(shù)據(jù),以element組件中的彈窗提示返回的結(jié)果,但vue中的this指向的是store,而使用element時this需要指向vue實例。
3.所以想著能把數(shù)據(jù)傳遞出去,在組件中去坐處理,組件中的this是指向vue實例的

回答
編輯回答
過客

this.$store.state

2017年8月31日 17:40
編輯回答
玩控

你是要在store文件里使用elm?
1:可以 import {Message}from 'element-ui';

    在store里單獨引入Message這個組件

2:在store 里 返回一個promise

在你的組件里調(diào)用這個action;然后在組建立獲取數(shù)據(jù),然后用this.$message
store actions : 你的請求方法 
async fn(){
        const res = await apiFn();
        if(){
            return x1
        }else{
            return x2
        }
    }
};

組件:
async tfn(){
    const res = await this.$store.dispath(actionName);
    if(x1){
        this.$message.success(res)
    }eles if(x2){
            this.$message.error(res)
    }
};
大概是這樣
2018年2月3日 17:59
編輯回答
尋仙

看下官網(wǎng)的這個示例

 const Counter = {
  template: `<div>{{ count }}</div>`,
  computed: {
    count () {
      return this.$store.state.count
    }
  }
}
2017年10月6日 11:17