为了账号安全,请及时绑定邮箱和手机立即绑定

vuex 中数据请求后返回的结果怎么传递到组件中去?

vuex 中数据请求后返回的结果怎么传递到组件中去?

慕村225694 2018-09-01 17:10:40
1.现在我在vuex的actions中用axios发送请求后台得到了数据。2.要处理这个数据,以element组件中的弹窗提示返回的结果,但vue中的this指向的是store,而使用element时this需要指向vue实例。3.所以想着能把数据传递出去,在组件中去坐处理,组件中的this是指向vue实例的
查看完整描述

2 回答

?
蝴蝶刀刀

TA贡献1801条经验 获得超8个赞

看下官网的这个示例

 const Counter = {
  template: `<div>{{ count }}</div>`,
  computed: {  
    count () {     
     return this.$store.state.count
    }
  }
}


查看完整回答
反对 回复 2018-09-09
?
阿晨1998

TA贡献2037条经验 获得超6个赞

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

在store里单独引入Message这个组件

2:在store 里 返回一个promise

在你的组件里调用这个action;然后在组建立获取数据,然后用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-09-09
  • 2 回答
  • 0 关注
  • 2298 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信