vuex

How to set values from a child component (settings page) using vuex store in a Vue.js app?

时间秒杀一切 提交于 2020-07-15 09:24:26
问题 I'm trying to create a "settings" component which saves selected values into a store so that all the other components can use those values to change their appearance. SettingsView.vue: One of the settings (you can also see it on codepen): [...] <p>{{ themeColor }}</p> <v-radio-group v-model="themeColor"> <v-radio label="light" value="light"></v-radio> <v-radio label="dark" value="dark"></v-radio> </v-radio-group> [...] <script> export default { data () { return { // default value themeColor:

Paginating firestore data when using vuex and appending new data to the state

巧了我就是萌 提交于 2020-07-10 10:27:09
问题 I implemented the following to display a paginated query (this was suggested by Tony O'Hagan in this post: How to get the last document from a VueFire query): bindUsers: firestoreAction(({ bindFirestoreRef }) => { return bindFirestoreRef('users', Firebase.firestore().collection('users').limit(8), { serialize }) }), bindMoreUsers: firestoreAction(context => { return context.bindFirestoreRef('users', Firebase.firestore().collection('users').startAfter(context.state.users[context.state.users

Uncaught FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined

懵懂的女人 提交于 2020-07-09 20:03:51
问题 I'm creating a e-commerce with Vue & Firebase. Trying to add some cart information from the current logged in user. Strange thing is at the very first time information saved perfectly. When I trying to add some again. That dosent work and show this error. Uncaught FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined So I have to refresh that page. Then it work again. I cant understand where is the problem. Note: If I try to add any other

What is the difference between Vuex and Event Bus?

早过忘川 提交于 2020-07-08 09:57:11
问题 I am trying to understand the principle of communication between components and a doubt has arisen: what is the main difference between Vue event bus strategy and Vuex to deal with components communication? Besides that, when is the best time of use of each one and what is the best practice to use both in the same project? 回答1: the vue event bus is a separate instance of Vue. Vuex is a (flux based) state managment library that integrates with the current instance of Vue, and adds a lot of

Async/Await with Vuex dispatch

≡放荡痞女 提交于 2020-07-05 07:10:50
问题 I am making a loader for some components in my app. Here is my component: mounted() { this.loading = true; this.getProduct(); }, methods: { async getProduct() { await this.$store.dispatch('product/getProducts', 'bestseller'); console.log(123); this.loading = false; } }, Vuex action: getProducts({commit}, type) { axios.get(`/api/products/${type}`) .then(res => { let products = res.data; commit('SET_PRODUCTS', {products, type}) }).catch(err => { console.log(err); }) }, The problem is in this

Async/Await with Vuex dispatch

删除回忆录丶 提交于 2020-07-05 07:08:46
问题 I am making a loader for some components in my app. Here is my component: mounted() { this.loading = true; this.getProduct(); }, methods: { async getProduct() { await this.$store.dispatch('product/getProducts', 'bestseller'); console.log(123); this.loading = false; } }, Vuex action: getProducts({commit}, type) { axios.get(`/api/products/${type}`) .then(res => { let products = res.data; commit('SET_PRODUCTS', {products, type}) }).catch(err => { console.log(err); }) }, The problem is in this

What exactly is namespacing of modules in vuex

◇◆丶佛笑我妖孽 提交于 2020-07-05 06:21:07
问题 I have recently started with vuex . The official docs explains well what modules are but i am not sure if i understood the namespaces in modules right. Can anybody put some light on namespaces in a better way? When/why to use it? Much appreciated. 回答1: When you have a big app with a very large state object, you will often devide it into modules. Which basically means you break the state into smaller pieces. One of the caveats is that you can't use the same method name for a module since it is

How to get vuex state from a javascript file (instead of a vue component)

北战南征 提交于 2020-07-04 07:36:26
问题 I am working with vuex (2.1.1) and get things working within vue single file components. However to avoid too much cruft in my vue single file component I moved some functions to a utils.js module which I import into the vue-file. In this utils.js I would like to read the vuex state. How can I do that? As it seems approaching the state with getters etc is presuming you are working from within a vue component, or not? I tried to import state from '../store/modules/myvuexmodule' and then refer

Global http response error handling in vue/axios with vuex

五迷三道 提交于 2020-07-03 09:39:45
问题 I'm trying to fix a behavior in my vue SPA which is basically a limbo state where the app doesn't know the JWT is already expired and therefore presents itself as if the user was still logged in. (this happens after hibernation for example) These users can keep on making any request to the API, but end up with a 401 response of course Now I would like to have a global handler for 401 responses. (which would be: "clear everything user-related from vuex and present the page as if the user was a

Global http response error handling in vue/axios with vuex

会有一股神秘感。 提交于 2020-07-03 09:39:37
问题 I'm trying to fix a behavior in my vue SPA which is basically a limbo state where the app doesn't know the JWT is already expired and therefore presents itself as if the user was still logged in. (this happens after hibernation for example) These users can keep on making any request to the API, but end up with a 401 response of course Now I would like to have a global handler for 401 responses. (which would be: "clear everything user-related from vuex and present the page as if the user was a