Vue3中获取vuex的state中数据

(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就行了

你可能感兴趣的:(vue,vue.js,前端,javascript)