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

蝴蝶刀刀
TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超8個(gè)贊
看下官網(wǎng)的這個(gè)示例
const Counter = { template: `<div>{{ count }}</div>`, computed: { count () { return this.$store.state.count } } }

阿晨1998
TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊
你是要在store文件里使用elm?
1:可以 import {Message}from 'element-ui';
在store里單獨(dú)引入Message這個(gè)組件
2:在store 里 返回一個(gè)promise
在你的組件里調(diào)用這個(gè)action;然后在組建立獲取數(shù)據(jù),然后用this.$message store actions : 你的請(qǐng)求方法 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) } }; 大概是這樣
添加回答
舉報(bào)
0/150
提交
取消