I have a page for listing data from table using Vue.js and Laravel. Listing data is successful. Delete and edit function is going on. For that purpose I have added two <span> (glyphicon-pencil), <span> (glyphicon-trash)
. If both <span>
are outside the <template>
tooltip shows, otherwise it doesn't works. Do you know how bootstrap tooltip works inside Vue Js. Thanks.
page.blade.php
<template id="tasks-template"> <table class="table table-responsive table-bordered table-hover"> <thead> <tr> <th>#</th> <th>Id</th> <th>Religion</th> <th>Action</th> <th>Created</th> <td>Status</td> </tr> </thead> <tbody> <tr v-for="(index, task) in list"> <td><input type="checkbox" id="checkbox" aria-label="checkbox" value="checkbox"></td> <td>@{{ index + 1 }}</td> <td>@{{ task.religion | capitalize }}</td> <td v-if="task.status == 'publish'"> <span class="glyphicon glyphicon-ok"></span> </td> <td v-else> <span class="glyphicon glyphicon-remove"></span> </td> <td>@{{ task.created_at }}</td> <td> <span class="glyphicon glyphicon-pencil" aria-hidden="true" data-toggle="tooltip" data-placement="left" title="Edit"></span> <span class="glyphicon glyphicon-trash" aria-hidden="true" data-toggle="tooltip" data-placement="right" title="Delete"></span> </td> </tr> </tbody> </table> </template> <tasks></tasks> @push('scripts') <script src="/js/script.js"></script> @endpush
scripts.js
$(function () { $('[data-toggle="tooltip"]').tooltip() }) Vue.component('tasks', { template: '#tasks-template', data: function(){ return{ list: [] }; }, created: function(){ this.fetchTaskList(); }, methods: { fetchTaskList: function(){ this.$http.get('/backend/religion/data', function(tasks){ this.$set('list', tasks); }); } } }); new Vue({ el: 'body' });
To create a tooltip using the component approach, we can simply create a button and put the ID in the target attribute. In the code above, we created a button called b-button and gave it a specific ID, tooltip-target-1 .
Initialize tooltips in bootstrap disabled buttons with the specified element and call the tooltip() method. To trigger tooltip on disabled button by wraping them in <span> span tag and <div> div tag and then adding 'data-toggle','data-placement' and 'title' attributes to it along with its values respectively.
With BootstrapVue you can build responsive, mobile-first, and ARIA accessible projects on the web using Vue. js and the world's most popular front-end CSS library — Bootstrap v4.
You can use this directive:
Vue.directive('tooltip', function(el, binding){ $(el).tooltip({ title: binding.value, placement: binding.arg, trigger: 'hover' }) })
For example:
<span class="label label-default" v-tooltip:bottom="'Your tooltip text'">
Or you can also bind the tooltip text to a computed variable:
<span class="label label-default" v-tooltip:bottom="tooltipText">
And in your component script:
computed: { tooltipText: function() { // put your logic here to change the tooltip text return 'This is a computed tooltip' } }
You need to run $('[data-toggle="tooltip"]').tooltip()
AFTER the data loads from the server. To ensure the DOM is updated, you can use the nextTick
function:
fetchTaskList: function(){ this.$http.get('/backend/religion/data', function(tasks){ this.$set('list', tasks); Vue.nextTick(function () { $('[data-toggle="tooltip"]').tooltip() }) }); }
https://vuejs.org/api/#Vue-nextTick
Edit: a more complete and robust solution has been posted by Vitim.us below
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With