for example, there are two pages of An and B, and when you want to modify the data of page A, the data of page B also changes at the same time. And when two pages are opened at the same time
I tried using Vuex, and found that after modifying the data on page A, the data on page B remained unchanged.
/ / A.vue
< template >
{{getName}}
<button @click="changeName" value=""></button>
{{getName}}
< / div >
< / template >
< script >
export default {
computed: {
getName(){
return this.$store.state.name
}
},
methods: {
changeName () {
this.$store.state.name = "newName"
//this.$store.commit("updateName")
}
}
}
< / script >
/ / B.vue
< template >
{{getName}}
< / div >
< / template >
< script >
export default {
computed: {
getName(){
return this.$store.state.name
}
}
}
< / script >
/ / store/index.js
import Vue from "vue"
import Vuex from" vuex"
Vue.use (Vuex)
export default new Vuex.Store ({
state: {
name: "oldName"
},
mutations: {
updateName (state) {
state.name = "newName"
}
}
})
first of all, it is impossible for you to open these two pages at the same time, so there are many ways to update data. And vuex can fully meet your needs. Please post the code
the value of Vuex can not be modified directly in this way, it is recommended to learn it first. You need to use mutations to modify
does this require a resident request like socket.io? Request regularly, find the back-end data update, and then get the new data.
-
Use vuex, to update the state, in stores. Why is it not updated in the view?
vue a rookie to solve, the code is component .vue <template> <div class="top-ad-section" v-bind:class="{ show: isShowAdStatus }">< div> < template> <script> export default { mounted() { setT...
-
After vuex uses module, the store.state. cannot be obtained from the beforeEnter in the routing file.
try to get store data in the route file, but the undefined vuexmodule modulestore is displayed. ...
Feb.27,2021 -
How to get vuex data in created cycle?
after searching around, I didn t see this tutorial. put the vuex data into the data before the dom is mounted, but the data is not available in the created. ...
-
VUEX assignment error report, but does not affect the use?
...
-
Using action to pass parameters to report errors in vuex
the configuration related to vuex is as follows < hr > const mutations = { incrementment( state,payload ){ state.numb+= payload.amount; }, reducement( state ){ state.numb-- ; }, [SOME_MUTATION](){ state.numb+...
-
I want to use some of the constants defined in state to assign default values to the drop-down box and v-model this variable in the data of the component, what should I do?
I m going to assign the default value of 1 to the value of the drop-down box and bind this variable; <select v-model= selectValue >< select> but just let data(){ return{ selectValue:1 } } this type of writing is not readable, so I ...
Mar.03,2021 -
Variables in Vue are rendered successfully, but input mutation is undefined?
data file mutations.js item.textdelete iditem.textpropundefined click question and answer:, mutation API accepts only two parameters ...
-
Vue refresh component, which refers to how another component refreshes the referenced component, or destroys it when another component calls another component. The simple point is that you need to refresh the current component.
I have referenced another component in one component. What can I do to refresh the referenced component when a value changes? or call the destroy method of another component in the current component ...
Mar.03,2021 -
Nuxt.js, how to call the mutation method in store in other js files?
I need the js file in plugins or assets to call the mutation method add . How can I call it correctly? ...
-
Vuex and browser caching
The main purpose of Vuex is to share and manage data, so why not just use browser caching? what is the fundamental difference between Vuex and browser caching strategy? the data flow in the Vuex state repository is unidirectional Synchronize, so why...
-
Why does the Vuex asynchronous method still work in mutations?
the official document says that asynchronous modification of the state will not take effect: https: vuex.vuejs.org zh-cn . but the following code does change the value: mutations: { increment: (state)=>{ window.fetch( https: jsonp...
-
How to understand the sentence that we can use the mapState helper function to help us generate calculation properties so that you can press the key a few times less?
in Vuex State document : when a component needs to acquire multiple states, declaring these states as computational properties can be repetitive and redundant. To solve this problem, we can use the mapState helper function to help us generate computa...
-
Methods can prompt undefined when $store.state, calls a method in methods in mounted.
A method in methods is called in mounted in the same component. but the use of error-free mounted in methods prompts $store is undefine as soon as it is called. Excuse me, what s going on? ...
-
About the problem of dynamic parameter transfer in css?
<div v-for="src of item.images" class="img2" :style="{backgroundImage: url( +src+ ) }">< div> item.images=[ http: xx 1.jpg , http: xx 2.jpg , http: xx 3.jpg ]; srcbackgroundImageurl : ...
-
The axios encapsulated by vue refers to vuex store and reports an error undefined.
Let s talk about the directory structure first: src api login.js store getters.js index.js modules user.js utils request.js axios the problem is that now I want to use vuex, in request.js, but after I intro...
Mar.19,2021 -
Apart from vuex, how can you easily set and get global variables in mpvue?
requirements: in the original Mini Program, the setting and acquisition of the user s openId was accomplished through the operation of App.gloabalData . Now using mpvue to develop a new Mini Program, how to deal with this kind of data that needs to b...
-
Get the getters,Cannot read property 'getters' of undefined of store
uses the login permission judgment in vue-element-admin, which is basically introduced and loaded according to it, but it still prompts you to report an error main.js . import Vue from vue import App from . App import router from . router i...
Mar.21,2021 -
Vuex and computed sometimes work, sometimes they don't update the page.
1. Two identical functions, same method, one valid, one invalid 2. Invalid code: <Row :gutter="10" style="margin-top: 10px" v-for="(col, index) in categoryList" :key="index"> <Col span="4"...
-
The problem of data loss after vuex refresh
vue project, after refreshing, the data in store is lost. I use localstorage to store it. When I take it out, I find that the page will report an error. I don t know why. Code: login: methods: { ...mapMutations([ SET_USER , ]), ...
-
After the vue login is successfully redirected, the registration status of the home login has not changed.
after the login is successful, save the login information to localStorage. The login registration should be changed to the user name on the home page after login, and the drop-down selection should be included. In the component, I judge which part of th...