vue-carousel无法读取未定义的属性“ forEach”

时间:2019-09-03 18:25:05

标签: javascript vue.js vuejs2 vue-component nuxt

我正在使用yarn安装vue-carousel,并添加复制自表单文档的模板代码。 那么就会出现一个错误,提示无法读取未定义的属性“ forEach”。

Frontend screenshot console screenshot

  • 节点/ npm版本:6.10.3
  • 操作系统:macOS 10.14.6(18G87)

Vue组件

<carousel>
    <slide>
        Slide 1 Content
    </slide>
    <slide>
         Slide 2 Content
    </slide>
</carousel>

plugins / main.js

import Vue from 'vue';
import Carousel3d from 'vue-carousel-3d';
import VueCarousel from 'vue-carousel';

Vue.use(VueCarousel);
Vue.use(Carousel3d);

nuxt.config.js

/*
  ** Plugins to load before mounting the App
  */
  plugins: [
    {src:'~/plugins/main.js',ssr:false}
  ],

1 个答案:

答案 0 :(得分:0)

您是否尝试过将Vue Carousel本地导入到您的组件中?

const orders = [
  {
    orderId: 1,
    orderLine: 1,
    itemId: 123,
    qty: 1
  },
  {
    orderId: 2,
    orderLine: 4,
    itemId: 123,
    qty: 2
  },
  {
    orderId: 3,
    orderLine: 7,
    itemId: 234,
    qty: 1
  },
  {
    orderId: 4,
    orderLine: 8,
    itemId: 123,
    qty: 1
  }
];

const available = [
  {
    itemId: 123,
    qty: 3
  },
  {
    itemId: 234,
    qty: 4
  }
];

// make a copy if you want to preserve the available object
// const availableCopy = JSON.parse(JSON.stringify(available));

const result = orders
  .map(({ orderId, qty, itemId }) => {
    const itm = available.find(e => e.itemId === itemId);
    itm.qty = itm.qty - qty;

    return itm.qty < 0 ? orderId : null;
  })
  .filter(e => e);

console.log(result);