简体   繁体   中英

How to render plugins jQuery (as tooltip and Switchery) with Vue.js on a Bootstrap Modal?

How are you doing? I hope well!

So I've got a template at ThemeForest (pure HTML + CSS + jQuery) and I am developing app in Vue.js + Laravel.

I am facing a problem when I have to make 2 plugins work (one is the Bootstrap Tooltip and other the Switchery ) inside a Bootstrap Modal.

I would like keep it as it is because I would not like the change the template =)

When I put it inside a View Component it simply does not work! There is my code, if somebody can help!

OBS: I make the code above a bit cleaner then the real one and I am using VUEIFY what I thinks it's not a problem!

BUTTON THET TRIGGERS THE MODAL

<a href="#" data-toggle="modal" data-target="#sources-modal">My Modal</a>

MY MODAL CODE

<template>

  <!-- Source -->
  <div id="sources-modal" class="modal fade" style="display: none;">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">Sources</h4>
        </div>
        <div class="modal-body">
          <div class="row p-10">
            <div class="col-md-6 m_md_bottom_15">
              <span class="waves-effect btn btn-warning" data-toggle="tooltip" data-original-title="Refresh" @click="fetchRecordList()"><i class="fa fa-refresh"></i></span>
            </div>
          </div>
          <div class="over_auto" v-el:data-grid>
            <table class="table table-striped table-bordered m-0">
              <thead>
                <tr>
                  <th class="w_50">
                    <input @click="selectAll()" v-model="allSelected" type="checkbox">
                  </th>
                  <th class="th_sort" @click="sort('name')" :class="isSortedColumn('name')">Name</th>
                  <th class="t_center th_sort w_100" @click="sort('active')" :class="isSortedColumn('active')">Active</th>
                  <th class="t_center w_100">Actions</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="r in list | filterBy tableFilter | orderBy sortProperty sortDirection" track-by="$index">
                  <td>
                    <input type="checkbox" v-model="selected" value="{{ r.id }}">
                  </td>
                  <td>{{ r.name }}</td>
                  <td class="t_center">
                    <input type="checkbox" data-plugin="switchery" data-color="#5fbeaa" data-size="small" v-model="r.active" />
                  </td>
                  <td class="t_center">
                    <span class="waves-effect btn btn-warning btn-xs" data-toggle="tooltip" title="Edit" @click="fillForm(r)"><i class="fa-fw fa fa-pencil"></i></span>
                    <span class="waves-effect btn btn-danger btn-xs" data-toggle="tooltip" title="Delete" @click="deleteRecord(r)"><i class="fa-fw fa fa-times"></i></span>
                  </td>
                </tr>
                <tr v-show="!list.length">
                  <td class="t_center" colspan="4">No records found</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>

</template>

HERE I EXTRACTED THE TOOLTIP AND SWITCHERY CODE FROM THE MODAL TO SHOW IT EASYER

<input type="checkbox" data-plugin="switchery" data-color="#5fbeaa" data-size="small" v-model="r.active" />
<span class="waves-effect btn btn-warning" data-toggle="tooltip" data-original-title="Refresh" @click="fetchRecordList()"><i class="fa fa-refresh"></i></span>

Somebody knows how to help me?

Thanks in advance!

Nobody!! hahahahaa Now that I've learned better how to work with view I will share my solution trying to help someone!

Just did 2 directives to make it work!

About Switchery I gave up from this jquery plugin and did by my own I component! You can checkout on this post Wrapping Switchery in a Directive VueJS

About tooltip

import Vue from 'vue';

Vue.directive('plTooltip', {
  params: [
    'animation',
    'container',
    'html',
    'placement',
    'trigger',
  ],

  bind: function() {
    $(this.el).tooltip({
      animation: this.params.animation || true,
      container: this.params.container || false,
      html: this.params.html || false,
      placement: this.params.placement || 'top',
      title: this.vm.$t(this.expression) || '',
      trigger: this.params.trigger || 'hover focus',
    });
  },
  unbind: function() {
    $(this.el).tooltip('destroy');
  }
});

I hope it helps someone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM