1

I try to use viewpoint and I Pass the values to my waypoint it send my this message: Uncaught Error: No element option passed to Waypoint constructor,I got my code like this:

in my view galeri.vue :

<template>
      <div class="play-top" id="final">
      <iframe src="xxxxxxxxx" allowfullscreen autoplay="false"></iframe>
    </div>
</template>


<script>
    require('waypoints/lib/jquery.waypoints.min.js')
    var ele
    var waypoint = new Waypoint({
      element: ele = document.getElementById('final'),
      handler: function(direction) {
        if (direction == 'down') {
          $(ele).addClass('muestra')
        } else {
          $(ele).removeClass('muestra')
        }
        console.log(direction);
      }
    });
<script>

any idea what I am doing wrong

4

1 回答 1

1

使用单文件组件,您需要实际导出一个 Vue 组件。所以你的脚本应该看起来像这样:

<script>
  require('waypoints/lib/jquery.waypoints.min.js')
  export default {
    mounted(){
      var ele
      new Waypoint({
        element: ele = document.getElementById('final'),
        handler: function(direction) {
          if (direction == 'down') {
            $(ele).addClass('muestra')
          } else {
            $(ele).removeClass('muestra')
          }
          console.log(direction);
        }
      });
    }
  }
<script>

这会将模板安装在 DOM 中,然后您的 Waypoint 脚本将运行。

于 2017-09-06T22:19:58.223 回答