Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Analysis of Special Application examples in vuex

Shulou Source: shulou.com Published: 2022-05-31 12:08:45 09月12日 Update

This article introduces the relevant knowledge of "Special Application case Analysis in vuex". In the operation of actual cases, many people will encounter such a dilemma, 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!

Requirements: in the vue project, I need a global-like variable to hold a tag value, modify this variable in subcomponents at different levels, and make the result of the change act on the component page.

Vuex is used here to solve the problem. The code is as follows:

Import Vue from 'vue'import Vuex from' vuex'Vue.use (Vuex); const state = {spinTag: false, / / spin component tag}; / / method to change the state const mutations = {spinTagTAG (state, tag) {state.spinTag = tag;}}; var store = new Vuex.Store ({state, mutations}); export default store

At this point, you can use the code in any subcomponent to modify the value and function in the component page as mentioned in my requirements.

This.$store.commit ('spinTagTAG', true); / / Open the spin component

This requirement stems from the fact that the spin component under antd vue cannot cover the entire browser and is on call, so I used vuex.

The code is as follows:

This is the end of the content of "Special Application case Analysis in vuex". Thank you for your 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: Components code requirements special instance instance analysis analysis application function content variables more knowledge pages different practical successful learning and then on call. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple NVidia macOS Linux MySQL