当我在[ACTYPE.GET_MOVIES]中调用分页器函数时,我正在尝试解决一个问题。
它向我显示了以下错误:
TypeError:_this.paginator不是eval的函数(actions.js? 63e0:13)
Store / Actions.js
import {ACTYPE} from './types/actions_types';
import {MUTYPE} from './types/mutations_types';
import {BASE_URL , TOP_MOVIES , QUERY_URL} from '../API_URLs/index';
import axios from 'axios';
const A = axios.create({ baseURL: String(BASE_URL) });
export const actions = {
[ACTYPE.GET_MOVIES]({commit} , page){
A.get(TOP_MOVIES).then((res) =>{
console.log(res);
const dataPaginated = this.paginator(res.data , page)
commit(MUTYPE.SET_MOVIES_DATA , dataPaginated);
commit(MUTYPE.IS_LOADING , false);
}).catch((err) =>{
console.log(err);
});
},
paginator(items, page, per_page){
var page = page || 1,
per_page = per_page || 10,
offset = (page - 1) * per_page,
paginatedItems = items.slice(offset).slice(0, per_page),
total_pages = Math.ceil(items.length / per_page),
paginContent = {
page: page,
per_page: per_page,
pre_page: page - 1 ? page - 1 : null,
next_page: (total_pages > page) ? page + 1 : null,
total: items.length,
total_pages: total_pages,
data: paginatedItems
};
console.log("Paginate Item: " , paginatedItems);
console.log("Pagin Content: " , paginContent);
return paginContent.data;
},
答案 0 :(得分:1)
您应该更改您的paginator(items, page, per_page){ ...
到function paginator(items, page, per_page){
这样,声明就被悬挂了。如果没有,则paginator
没有声明。
然后您可以删除this
中的this.paginator(res.data , page)
完成后应该可以工作