我在[ACTYPE.GET_MOVIES]中调用分页器函数时试图解决问题。

它向我显示了以下错误:


  TypeError:_this.paginator不是eval的函数(actions.js?
  63e0:13)


商店/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;
 },

最佳答案

您应该更改您的paginator(items, page, per_page){ ...

function paginator(items, page, per_page){

这样,声明就被悬挂了。如果不是,则不声明paginator

那么您可以在this中删除​​this.paginator(res.data , page)

完成后,它应该工作

关于javascript - vuex存储/操作中的分页问题[this.paginator不是函数],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54988899/

10-09 23:41