解决Vue3使用store,数据undifind
原先在组件中的代码
<script setup>
function mounted(){
this.$slots.dispatch('getCategory');
};
mounted();
</script>
但因为在setup语法糖中不支持this,在网上找了很久的解决办法也没有找到,最后尝试去理解,修改成功
修改后的代码
<script setup>
import store from '@/store/index.js'
function mounted(){
store.dispatch('getCategory');
};
mounted();
</script>
这样就可以成功获取数据了