actions.js:
export const fetchRoomLists = ({commit}, cname, limit) => {
const url = `/live/${cname}`
const query = `offset=0&limit=${limit}`
return _get({ url, query }, commit)
.then((json) => {
if (json.error === 0) {
// return commit('FETCH_ROOM_LIST_SUCCESS', json.data)
console.log(query)
}
return Promise.reject(new Error('FETCH_ROOM_LIST_SUCCESS failure'))
})
.catch((error) => {
return Promise.reject(error)
})
在vue文件的dispatch:
mounted () {
this.$store.dispatch('fetchRoomLists', this.$route.params.id, 30)
},
console出来是这样的:

有谁知道是什么问题么?搞半天没搞懂?明明定义了,但是第二个参数一直是undefined,但是一个参数又不会~
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
代码貌似没有贴全,不知道你的action有没有在vuex中注册,然后是调用action派发mutation,然后在那个调用action的函数中打印一下$route看看是不是组件生命周期的问题
看样子你用的是
vue2,那么问题来了,从源码看(当然从api文档看也一样),dispatch最多就只接受两个参数,type和payload,所以你说你传的, 30总是undefined对吧?那就对了,源码地址:vuex
文档地址:vuexstore-methods
请问题主是如何解决的