the best solution is to use vuex? Why can"t the values in store be assigned directly in data, but must be in computed?
I need each component to have a computed to receive the array in these store.
can anyone give me an example? thank you
the best solution is to use vuex? Why can"t the values in store be assigned directly in data, but must be in computed?
I need each component to have a computed to receive the array in these store.
can anyone give me an example? thank you
this actually depends on the scene.
if you retrieve the array in the background, it will not change, which is equivalent to a static constant.
for example: ALL_ROLES = ['student',' teacher']
in this way, you can store it in localStorage, pick it up when you need it, and fetch it on the server if you don't have it before you go, which is also very ok. The only drawback may be that the ilocalStorage O of Synchronize is a little slower.
if your array changes from time to time, and several arrays rely on a "live" singleton data, it's best to put it in store. It is also very simple to write. Components that depend on this array dispatch the action, of fetch data every time they created, and then mapGetters is mapped to the component computed. Pseudocode:
// ExComponent.vue
import {mapGetters} from 'vuex'
created () {
this.$store.dispatch('fetchArrData')
},
computed: {...mapGetters(['arr'])}
it's so simple and cool that you can't find a more elegant way
you can't just save it in localStorage?
vuex learn about
use vuet's mapRules to solve this problem perfectly, and the author developed this for car racing.
<template>
<div class="txt-left txt-b-info">:{{menuEdit.form.name}}</div>
</template>
isn't that what vuex is for?
Previous: What simulator is better to debug on mac developed by android?
Next: Failure to obtain data often occurs during sqlalchemy operation, but there is data in mysql.
The problem with is that I have a vue plug-in (which uses vue install exports and can use plug-ins introduced by vue.use ()), and I want to use vuex to communicate between components in this plug-in. currently there are the following problems: what I...
The page is normal, but there are errors reported. generally circulate the data of vuex directly in v-for, or add the data of vuex to the data of this page in created. ...
...
use action to delete array objects in the container how to solve the page jam, and is it possible to delete multiple objects in the array without a loop? ...
The value 2 passed in during the call will not be passed into the state parameter? But directly to the id? how to implicitly pass in state? The expression of learning C is not quite understood. No, no, no. ...
< hr > speaking vuex , then some people will say that this is done in state management in large-scale projects. Recently, I have been learning this part of the content. I would like to ask you a few questions . vuex Local StorageSession Storage? ...
through vuex, it seems that you need to create an extra state variable, and then modify the state through component A, while component B listens for changes in the state, thus realizing the transmission of events. But it feels like the value of this sta...
weex uses vuex to report errors Uncaught ReferenceError: Vue is not defined if I introduce import Vue from vue into vuex index.js, the webside will display normally, and if I don t introduce iOS, the following is my code and error report. Ple...
as shown in the figure, are there any ideas or ready-made plug-ins? elementUI looked at it and found that it could not support dynamic component switching. ...
when namespaced is not used, actions is registered globally by default, but after use, actions will become under the module, but I don t want to do this. I also want it to be global. My namespace:true is just for the convenience that I introduce state, ...
there are more than 10 methods for methods in one of my .vue files, and this page looks messy. is it because my componentization is not thorough enough; is there any way to make the file more concise ...
how do I reassign vue.$user.element? there is something wrong with my writing. There has been no output of value . ...
I want a variable in the drop-down box v-model data, and the default value of this variable is the constant defined in state, but what if it doesn t change with the value in state? reference: https: codeshelper.com q 10. The value of computed canno...
wants to send the collected data when switching routes, but does not generate when changing the value of vuex. beforeRouteLeave: (to, from, next) => { try { console.log(":"+new Date().getTime()); this.$store.commit( GET_HTTPRESP...
1, vue 2.5.13 can be obtained normally, and then the version cannot be obtained 2. Code: .vue file: computed: { ...mapGetters({ packages: getPackageByTag_data , pagerData: getPackagesPager , }), }, in the pkg.js of modu...
A rookie, who had no choice but to turn to the god of Sifou for several days question: I use the vue init webpack project name to build the project: package webpack.base.conf.js index.js run dev route.js drawer.vue ...
A property of state is used in both components. One component modifies this property, but the other component does not update the data ...
previously stored the data in vuex, and got it in a page my guess is that when the page is rendered, the cpmputed does not getter the data at the beginning, so the corresponding attribute cannot be found when the value is assigned, and then the ...
as shown in the figure, I get the data in vuex in created. I can get it as soon as I enter the page, but I can t get the data after the page is refreshed ...
font settings for browsers such as uc or qq. Can you dynamically control the app font size? Solve the problem, if it is too troublesome to write with js ...