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'
});
Bootstrap Vue supports tooltips directly via the following syntax documented here.
Installation of Bootstrap Vue is quick and painless. See the quick setup guide for more details.
The right way to this, is making it a directive, so you can hook on the life cycle of a DOM element.
https://vuejs.org/v2/guide/custom-directive.html
https://gist.github.com/victornpb/020d393f2f5b866437d13d49a4695b47
You can use this directive:
For example:
Or you can also bind the tooltip text to a computed variable:
And in your component script:
You will find all the CDNs here without requirement of any registration of directive. Libray was made by Guillaume Chau
If the tooltip does not show on your page, most probably it is conflicting with some other library or the order of placing the CDNs on the page is not proper. In case your tooltip is being cut off on Chrome (will work in FireFox) due to conflict with bootstrap library, add max-width:100% to tooltip-inner to the v-tooltip style
You should use this syntax, put it on index.html or on your general js file
If using Typescript Vue class components, install the jquery types:
And declare the directive like this in your Vue file, outside your component:
Then use the sample HTML/bindings from @Ikbel's answer.