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

JULIO MACHAN
  • 161
  • 1
  • 2
  • 13
  • Where is the Vue component that renders the template? – Bert Sep 06 '17 at 22:07
  • I am using vue+rails I create it in a folder call it pack like the code above and them I insert it in the rails view like this : **<%= javascript_pack_tag 'folder/file_vue' %>** – JULIO MACHAN Sep 06 '17 at 22:16
  • Ok, but the script above doesn't export a Vue component. You'll need to convert it into one. – Bert Sep 06 '17 at 22:17

1 Answers1

1

With single file components, you need to actually export a Vue component. So your script should instead look something like this:

<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>

This will mount the template in the DOM and then your Waypoint script will run.

Bert
  • 80,741
  • 17
  • 199
  • 164