这是我的商店: store / index.js
import { of, merge, BehaviorSubject } from 'rxjs';
import { switchMap } from 'rxjs/operators';
const s = new BehaviorSubject([of(1), of(2), of(3)]);
s.pipe(
switchMap(array => merge(...array)),
).subscribe(x => console.log(x));
s.next([...s.getValue(), of(4)]);
问题是export const state = () => ({
userLocation: {}
})
export const mutations = {
setUserLocation(state, payload) {
state.userLocation = payload
console.log(payload)
}
}
export const actions = {
async fetchUserLocation({ commit }) {
const { data } = await this.$axios.get(
`${process.env.IPGEO_URL}?apiKey=${process.env.IPGEO_TOKEN}`
)
commit('setUserLocation', data)
}
}
突变不会改变setUserLocation
状态,并且不会更新。