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
}
}
}
阿晨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)
}
};
大概是这样添加回答
举报
0/150
提交
取消
