Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Installation and use of vuex

Shulou Source: shulou.com Published: 2022-06-02 04:42:33 09月21日 Update

This article introduces the relevant knowledge of "the installation and use of vuex". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Install vuexnpm install vuex-SHelloworld

Create a new directory store under the src directory of the project, and create a new index.js file under this directory, which we use to create a vuex instance, then introduce vue and vuex into the file, create a Vuex.Store instance and save it to the variable store, and finally use export default to export store:

Import Vue from 'vue'; / / first introduce vueimport Vuex from' vuex' / / introduce vuexVue.use (Vuex) export default new Vuex.Store ({state: {/ / state similar to data / / write data}, getters: {/ / getters similar to computed / / write method}, mutations: {/ / mutations similar to methods / / write method to make changes to the data (synchronous operation)} Actions: {/ / actions is similar to methods / / write method to make changes to the data (asynchronous operation)})

Introduce this file into the main.js file, add import store from'. / store';, to the file, and then introduce the store object globally in the vue instance.

Import Vue from 'vue'import App from'. / App.vue'import router from'. / router'import store from'. / store'Vue.config.productionTip = falsenew Vue ({router, store, render: h = > h (App)}). This is the end of the $mount ('# app') "installation and use of vuex. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Methods files instances data directories usage content more knowledge practicality learning and then global variables dilemmas reality objects situations articles cases Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia Docker Huawei Redmi