Within my MVC project, I have successfully integrated Vue3 with Vuex4. However, I have encountered an issue specifically related to the mapState function.
Upon using the following import statements, an error is triggered:
import Vue from 'vue';
import Vuex from 'vuex';
1 Uncaught SyntaxError: Cannot use import statement outside a module
To resolve this issue, I included these files in my _Layout page:
<script src="~/lib/vue/vue.global.js"></script>
<script src="~/lib/vuex/vuex.global.js"></script>
At present, the solution seems to be effective. Though, when attempting to utilize mapState, I am faced with a dilemma and uncertain on how to approach it,
import { mapState } from 'vuex';
I attempted to locate a mapState.js file without success or found files containing limited code that did not yield any results...
const store = new Vuex.Store({
state: {
count: 0
}
})
const homeIndex = {
data() {
return {
}
},
computed: mapState({
count: state => state.count,
})
}
Vue.createApp(homeIndex).mount("#app");