vuex中提供useStore 在setup中可以使用
useStore ===vue2.0中的this.$store
import { useStore } from 'vuex'
export default {
setup () {
// 在setup中获取store
const store = useStore()
//根据computed获取store的state
const catagryList = computed(() => {
return store.state.catagory.catagryList
})
onMounted(() => {
store.dispatch('catagory/getCatagroy')
})
return { catagryList }
}
}
</script>
注意: userStore() 调用生效 不然报错