Build Vuex environment Create a folder // scr/vuex/index.js // Import Vuex import Vuex from 'vuex' // Used to respond to actions in components const actions = {} // Used to manipulate data const mutations = {} // Used to store data const state = {} // Create a store const store = new Vuex.Store({ actions, mutations, state }) // Export store export default store // main.js import Vue from 'vue' import App from './App.vue' import Vuex from 'vuex' import store from './store/index' Vue.use(Vuex) new Vue({ render:h => h(App), store }).$mount('#app') But this will result in an error:
Meaning : [vuex] Reason : When we import the store, the code of the imported file is executed first, so when the following code is executed, the imported file has been executed In this case, let's swap the two lines of code: But the actual result is: Reason : This is a problem with the scaffold parsing import statements. The imported file will be placed at the beginning of the code, and then the code of this file will be parsed. Correct way to write it: // scr/store/index.js // Import Vuex and Vue import Vuex from 'vuex' import Vue from 'vue' // Apply Vuex plugin Vue.use(Vuex) // Used to respond to actions in components const actions = {} // Used to manipulate data const mutations = {} // Used to store data const state = {} // Create a store const store = new Vuex.Store({ actions, mutations, state }) // Export store export default store // main.js import Vue from 'vue' import App from './App.vue' import store from './store/index' new Vue({ render:h => h(App), store }).$mount('#app') Summarize This article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Parsing Linux source code epoll
>>: Detailed explanation of the use of base tag in HTML
1. Download the image docker pull selenium/hub do...
1. Use the mysql/mysql-server:latest image to qui...
This article shares the data display code for Jav...
Table of contents 1. Steps to use Jquery: (1) Imp...
Preface: This article refers to jackyzm's blo...
Recently, when I was doing a practice project, I ...
MySQL is a relational database management system ...
step: 1. Create a new docker-compose.yml file in ...
Today, this article introduces some basic concept...
Docker provides a way to automatically deploy sof...
The interviewer will sometimes ask you, tell me h...
MySQL is a relational database management system ...
1. Introduction to VMware vSphere VMware vSphere ...
<br />The website access speed can directly ...
Table of contents 1. The origin of tomcat 1. Tomc...