vuex

Vuex - 'do not mutate vuex store state outside mutation handlers'

眉间皱痕 提交于 2020-05-29 08:07:29
问题 I'm trying to initialize my Vuex store from Firestore. The last line of code context.commit('SET_ACTIVITIES', acts) is what creates the error. I don't think I'm mutating the state directly since I'm using an action. What could I be missing? Here's my Vuex store: export default new Vuex.Store({ strict: true, state: { activities: [] }, mutations: { SET_ACTIVITIES: (state, activities) => { state.activities = activities }, }, actions: { fetchActivities: context => { let acts = [] let ref = db

Differences b/n mapState, mapGetters, mapActions, mapMutations in Vuex

你说的曾经没有我的故事 提交于 2020-05-24 20:29:55
问题 I have been using vue/vuex for months and I see mapState , mapGetters , mapActions , mapMutations but don't know what they do except for mapState . This is how I use mapState // mutations.js user: { address: {}, name: '', age: '' } and in my code I have something like this: import { mapState } from 'vuex' export default { data: {}, computed: { ...mapState({ address: state => state.user.address }) } } then I can use address anywhere, but I don't know what the others are used for. can someone

How to access the getter from another vuex module?

青春壹個敷衍的年華 提交于 2020-05-24 11:19:10
问题 Within a vuex getter I know it is possible to access the state from another vuex module like so: pages: (state, getters, rootState) => { console.log(rootState); } How can I access a getter from another vuex module instead of the state though? I have another vuex module called filters that I need to access, I have tried this: rootState.filters.activeFilters Where activeFilters is my getter but this does not work. using rootState.filters.getters.activeFilters also does not work. 回答1: Had to dig

How to access the getter from another vuex module?

痴心易碎 提交于 2020-05-24 11:18:15
问题 Within a vuex getter I know it is possible to access the state from another vuex module like so: pages: (state, getters, rootState) => { console.log(rootState); } How can I access a getter from another vuex module instead of the state though? I have another vuex module called filters that I need to access, I have tried this: rootState.filters.activeFilters Where activeFilters is my getter but this does not work. using rootState.filters.getters.activeFilters also does not work. 回答1: Had to dig

Missing param for named route: Expected “x” to be defined

断了今生、忘了曾经 提交于 2020-05-14 18:27:13
问题 Whether I do this Vue.router.push({ path: '/beats/catalog/1' }) or this Vue.router.push({ name: 'BeatsCatalog', params: { page: 1 } }) I get the same result: [vue-router] missing param for named route "BeatsCatalog": Expected "page" to be defined. Router: { path: '/beats', components: { navbar: Navbar, default: { template: `<router-view/>` } }, children: [{ name: 'BeatsCatalog', path: 'catalog/:page', components: { default: () => import('@/views/BeatsCatalog') }, props: { default: true } }, {

Missing param for named route: Expected “x” to be defined

隐身守侯 提交于 2020-05-14 18:27:06
问题 Whether I do this Vue.router.push({ path: '/beats/catalog/1' }) or this Vue.router.push({ name: 'BeatsCatalog', params: { page: 1 } }) I get the same result: [vue-router] missing param for named route "BeatsCatalog": Expected "page" to be defined. Router: { path: '/beats', components: { navbar: Navbar, default: { template: `<router-view/>` } }, children: [{ name: 'BeatsCatalog', path: 'catalog/:page', components: { default: () => import('@/views/BeatsCatalog') }, props: { default: true } }, {

How exactly does the spread syntax (…) work with mapGetters?

六月ゝ 毕业季﹏ 提交于 2020-05-11 03:58:36
问题 Whenever you want to use a computed getter with the mapGetter helper from Vuex you would use it like so: ...mapGetters([ 'getter1', 'getter2', 'etc' ]) I have seen the spread operator used before to expand arrays to be used as function arguments, but not in front of a method like we see here with the mapGetters example. I can't really find examples of this syntax either, when looking in mozilla documentation for example: https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Operators

How to correctly use Vue JS watch with lodash debounce

元气小坏坏 提交于 2020-05-10 07:19:30
问题 I'm using lodash to call a debounce function on a component like so: ... import _ from 'lodash'; export default { store, data: () => { return { foo: "", } }, watch: { searchStr: _.debounce(this.default.methods.checkSearchStr(str), 100) }, methods: { checkSearchStr(string) { console.log(this.foo) // <-- ISSUE 1 console.log(this.$store.dispatch('someMethod',string) // <-- ISSUE 2 } } } Issue 1 is that my method checkSearchStr doesn't know about foo Issue 2 is that my store is undefined as well

access store outside of component vuejs

為{幸葍}努か 提交于 2020-05-10 03:53:22
问题 I have a file for configuring my OpenID Connect authentication export const authMgr = new Oidc.UserManager({ userStore: new Oidc.WebStorageStateStore(), authority: **appsetting.oidc** }) I want to access my state in order to get the value of appsetting. I did this: import store from './store' const appsetting = () => store.getters.appsetting but my appsetting is always returning undefined what I my missing? Store: app.js const state = { appsetting: appsetting, } export { state } getters.js

access store outside of component vuejs

别等时光非礼了梦想. 提交于 2020-05-10 03:52:48
问题 I have a file for configuring my OpenID Connect authentication export const authMgr = new Oidc.UserManager({ userStore: new Oidc.WebStorageStateStore(), authority: **appsetting.oidc** }) I want to access my state in order to get the value of appsetting. I did this: import store from './store' const appsetting = () => store.getters.appsetting but my appsetting is always returning undefined what I my missing? Store: app.js const state = { appsetting: appsetting, } export { state } getters.js