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
Table of contents Preface 1.v-show 2.v-if 3. The ...
Table of contents use Use of EsLint Add a profile...
<br />First of all, I have to state that I a...
Table of contents Use of this.$set in Vue use Why...
Preface This article uses pdo's preprocessing...
How to check where the metadata lock is blocked i...
And, many times, maintenance requires your website...
Deleting a single table: DELETE FROM tableName WH...
Due to the limitation of CPU permissions, communi...
Encapsulate a navigation bar component in Vue3, a...
#!/bin/bash #Download SVN yum -y install subversi...
1. Some tips on classes declared with class in re...
Find the containerID of tomcat and enter the toma...
MySQL official website: https://www.mysql.com/dow...
<br /> Focusing on the three aspects of text...