VueJS/VueX 超出最大调用堆栈大小
VueJS/VueX Maximum call stack size exceeded
我目前正在做一个 Vue 项目,我正在使用 Vuex 进行状态管理。但是,当我在我的组件中使用 mapactions 和 mapgetters 绑定下面的两个操作时,我在控制台中收到 超出最大调用堆栈大小 错误。
我不知道我做错了什么。
import Vue from 'vue'
import Vuex from 'vuex'
import service from "../services/statisticsService"
import moment from 'moment'
Vue.use(Vuex)
const state = {
customersAndServicesOverTime:[],
counters:{}
}
const actions = {
actGetAllData(context){
context.dispatch('actGetCustomersAndServicesOverTime')
context.dispatch('actGetCounters')
},
actGetCustomersAndServicesOverTime(context){
service.getCustomerAndServicesOverTime(context.getters.getJWT)
.then(response =>{
context.commit('mutCustomersAndServicesOverTime', response.body)
})
},
actGetCounters(context){
service.getCounts(context.getters.getJWT)
.then(response =>{
context.commit('mutCounts', response.body)
})
}
}
const mutations = {
mutCustomersAndServicesOverTime(state,payload){
state.customersAndServicesOverTime ={
labels:payload.map(x => moment(x.created).format("DD-MM-YYYY")),
datasets:[{
data:payload.map(x => x.customersCount),
backgroundColor:"rgba(52, 73, 94,0.5)",
label:"customers",lineTension:0
},{
data:payload.map(x => x.servicesCount),
backgroundColor:"rgba(230, 126, 34,0.5)",
label:"services",lineTension:0
}]}
},
mutCounts(state,payload){
state.counters = payload
},
}
const getters = {
getCustomersAndServicesOverTime:state=>state.customersAndServicesOverTime,
getCounts:state=>state.counters,
}
export default {
state,
getters,
actions,
mutations
}
在我的服务中,我声明了两个与我的 API 连接的函数。
import Vue from 'vue'
import VueResource from 'vue-resource'
import CONFIG from "../config"
export default {
getCounts(jwt) {
return Vue.http.get(CONFIG.API + "statistics/counts", {
headers: {
'Content-Type': 'application/json'
,'Authorization': 'Bearer ' + jwt
}
})
},
getCustomerAndServicesOverTime(jwt) {
return Vue.http.get(CONFIG.API + "statistics/customersandservicesovertime", {
headers: {
'Content-Type': 'application/json'
,'Authorization': 'Bearer ' + jwt
}
})
}
}
这不是 vuex 问题。我使用 vue-chartjs,我没有硬拷贝我的对象实例,而是将它用作参考。这会导致超出最大调用堆栈大小错误。
我目前正在做一个 Vue 项目,我正在使用 Vuex 进行状态管理。但是,当我在我的组件中使用 mapactions 和 mapgetters 绑定下面的两个操作时,我在控制台中收到 超出最大调用堆栈大小 错误。
我不知道我做错了什么。
import Vue from 'vue'
import Vuex from 'vuex'
import service from "../services/statisticsService"
import moment from 'moment'
Vue.use(Vuex)
const state = {
customersAndServicesOverTime:[],
counters:{}
}
const actions = {
actGetAllData(context){
context.dispatch('actGetCustomersAndServicesOverTime')
context.dispatch('actGetCounters')
},
actGetCustomersAndServicesOverTime(context){
service.getCustomerAndServicesOverTime(context.getters.getJWT)
.then(response =>{
context.commit('mutCustomersAndServicesOverTime', response.body)
})
},
actGetCounters(context){
service.getCounts(context.getters.getJWT)
.then(response =>{
context.commit('mutCounts', response.body)
})
}
}
const mutations = {
mutCustomersAndServicesOverTime(state,payload){
state.customersAndServicesOverTime ={
labels:payload.map(x => moment(x.created).format("DD-MM-YYYY")),
datasets:[{
data:payload.map(x => x.customersCount),
backgroundColor:"rgba(52, 73, 94,0.5)",
label:"customers",lineTension:0
},{
data:payload.map(x => x.servicesCount),
backgroundColor:"rgba(230, 126, 34,0.5)",
label:"services",lineTension:0
}]}
},
mutCounts(state,payload){
state.counters = payload
},
}
const getters = {
getCustomersAndServicesOverTime:state=>state.customersAndServicesOverTime,
getCounts:state=>state.counters,
}
export default {
state,
getters,
actions,
mutations
}
在我的服务中,我声明了两个与我的 API 连接的函数。
import Vue from 'vue'
import VueResource from 'vue-resource'
import CONFIG from "../config"
export default {
getCounts(jwt) {
return Vue.http.get(CONFIG.API + "statistics/counts", {
headers: {
'Content-Type': 'application/json'
,'Authorization': 'Bearer ' + jwt
}
})
},
getCustomerAndServicesOverTime(jwt) {
return Vue.http.get(CONFIG.API + "statistics/customersandservicesovertime", {
headers: {
'Content-Type': 'application/json'
,'Authorization': 'Bearer ' + jwt
}
})
}
}
这不是 vuex 问题。我使用 vue-chartjs,我没有硬拷贝我的对象实例,而是将它用作参考。这会导致超出最大调用堆栈大小错误。