Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不刷新组件的情况下,改变slideritem数量,执行轮播报错 #74

Closed
lingyun1111 opened this issue Jan 23, 2019 · 2 comments

Comments

@lingyun1111
Copy link

需求是进入页面后ajax得到要展示的数据,在前端格式化通过轮播的展示

  • this.carousel.list 是我存放数据的对象

我经验不足,目前的做法是通过computed处理,把一个长数组分为二维数组。

  computed: {
    carouselMain() {
      let result = [];  //声明一个新数组
      //按配置的数量分好页
      for(var i=0,len=this.carousel.list.length;i<len;i+=this.carousel.max){
        result.push(this.carousel.list.slice(i,i+this.carousel.max));
      }
      return result
    },
  },

得到新的对象后,进行渲染

    <slider ref="slider" :options="options" @slide='slide' @init="init">
      <slideritem v-for="(n,i) in carouselMain" :key="i" style="display: block">
        <div class="flex" v-for="(item,index) in n" :key="n.QUEUE_ID">
          <!--内容-->
        </div>
      </slideritem>
    </slider>

this.carousel.list会根据websocket的消息实时更新长度
这个时候报错

### Uncaught TypeError: Cannot read property 'offsetLeft' of undefined
    at a.get (module.js:1)
    at De.get (vue.esm.js:3142)
    at De.evaluate (vue.esm.js:3249)
    at a.currentWidth (vue.esm.js:3507)
    at a.slide (module.js:1)
    at a.next (module.js:1)
    at module.js:1

如何在不重载组件的情况下处理数据的更新?

@warpcgd
Copy link
Owner

warpcgd commented Jan 23, 2019

临时的解决方式是,在数组变动的时候,将slider切换到第一页

this.$refs.slider.$emit('slideTo', 0)

在下一个版本,我会对这个错误进行处理

@lingyun1111
Copy link
Author

临时的解决方式是,在数组变动的时候,将slider切换到第一页

this.$refs.slider.$emit('slideTo', 0)

再下一个版本,我会对这个错误进行处理

感谢,我目前是监听slideritem的数量,变动后执行处理方法。
期待你的更新

@warpcgd warpcgd closed this as completed Feb 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants