Issue with foundation used in .vue single file com

2019-03-04 08:33发布

I have realised that there is a problem when using Zurb Foundation classes in .vue single file components. At first I could not get a Reveal Modal to work inside the .vue component but it was working when I use the same code in a blade or html file. Then I noticed a pattern because when I tried to use the Foundation's Orbit inside the component it failed, at first I thought it was an error but then I used the same code in a blade file and it worked. Other foundation classes such as row, grid and buttons are working just fine.

Has anyone experienced the same issue? And how can I work around it?

Here is the code for the modal:

<a data-open="video" class="button warning" href="">WATCH VIDEO</a>

<div id="video" class="reveal" data-reveal>
    <div class="lead">
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    <div class="flex-video">
        <iframe width="1280" height="720" :src="url" frameborder="0" allowfullscreen></iframe>
    </div>
</div>

And for the orbit I used the basic example in the foundation docs for testing.

    <div class="orbit" role="region" aria-label="Favorite Space Pictures" data-orbit>
  <ul class="orbit-container">
    <button class="orbit-previous"><span class="show-for-sr">Previous Slide</span>&#9664;&#xFE0E;</button>
    <button class="orbit-next"><span class="show-for-sr">Next Slide</span>&#9654;&#xFE0E;</button>
    <li class="is-active orbit-slide">
      <img class="orbit-image" src="assets/img/orbit/01.jpg" alt="Space">
      <figcaption class="orbit-caption">Space, the final frontier.</figcaption>
    </li>
    <li class="orbit-slide">
      <img class="orbit-image" src="assets/img/orbit/02.jpg" alt="Space">
      <figcaption class="orbit-caption">Lets Rocket!</figcaption>
    </li>
    <li class="orbit-slide">
      <img class="orbit-image" src="assets/img/orbit/03.jpg" alt="Space">
      <figcaption class="orbit-caption">Encapsulating</figcaption>
    </li>
    <li class="orbit-slide">
      <img class="orbit-image" src="assets/img/orbit/04.jpg" alt="Space">
      <figcaption class="orbit-caption">Outta This World</figcaption>
    </li>
  </ul>
  <nav class="orbit-bullets">
    <button class="is-active" data-slide="0"><span class="show-for-sr">First slide details.</span><span class="show-for-sr">Current Slide</span></button>
    <button data-slide="1"><span class="show-for-sr">Second slide details.</span></button>
    <button data-slide="2"><span class="show-for-sr">Third slide details.</span></button>
    <button data-slide="3"><span class="show-for-sr">Fourth slide details.</span></button>
  </nav>
</div>

2条回答
女痞
2楼-- · 2019-03-04 09:15

There is an issue when using vue components with foundation js components and that's why they are not showing as explained here

So I added this directive in my script tag:

Vue.directive('f-orbit', {
    bind: function (el) {
        new Foundation.Orbit($(el))
    },
    unbind: function (el) {
        $(el).foundation.destroy()
    }
})

And in my template I added v-f-orbit instead of the default data-orbit:

<div class="contemporary orbit" role="region" aria-label="Contemporary Pictures" v-f-orbit>

I hope this will assist someone who is stuck.

查看更多
劫难
3楼-- · 2019-03-04 09:15

Phillis's answer above is absolutely correct. Just thought I would throw in another example, of a Foundation 6.4 dropdown-menu and Vue.js 2.

Create the custom directive called dropdown and add v-dropdown to the parent element and it should be working.

        <ul class="dropdown menu" v-dropdown>
          <li>
            <a href="#">Navigate Site &nbsp;<i class="fas fa-chevron-down"></i></a>
            <ul class="menu vertical">
              <li><a href="/auto"><i class="far fa-car"></i>&nbsp; Auto</a></li>
              <li><a href="/residential"><i class="far fa-home"></i>&nbsp; Residential</a></li>
              <li><a href="/commercial"><i class="far fa-building"></i>&nbsp; Commercial</a></li>
              <li><a href="/safety-security"><i class="far fa-building"></i>&nbsp; Safety &amp; Security</a></li>
              <li><a href="/specialty-solutions"><i class="far fa-gem"></i>&nbsp; Specialty Solutions</a></li>
              <li><a href="/dealers"><i class="fal fa-id-badge"></i></i>&nbsp; Dealers</a></li>
              <li><a href="/madicou"><i class="far fa-building"></i>&nbsp; Madico U</a></li>
              <li><a href="/about"><i class="far fa-building"></i>&nbsp; Company</a></li>
            </ul>
          </li>
        </ul>

Vue.directive('dropdown', {
  bind: function (el) {
    new Foundation.DropdownMenu($(el));
  }
});
查看更多
登录 后发表回答