Vue3中获取vuex的state中数据
1)使用computed一个一个解析。(2)使用mapState全部解析。
·
(1)使用computed一个一个解析
import {useStore} from 'vuex'
import {computed} from 'vue'
const store=useStore()
const state=computed(()=>store.state.name)
(2)使用mapState全部解析
const storeState=mapState(['count','name'])
const state={}
Object.keys(storeState).forEach(Key=>{
const fn=storeState[Key].bind({$store:store})
state[Key]=computed(fn)
})
返回...state就行了
更多推荐
已为社区贡献3条内容
所有评论(0)