How can add bootstrap tooltip inside Vue.js

后端 未结 8 1488
失恋的感觉
失恋的感觉 2020-12-13 13:26

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

相关标签:
8条回答
  • 2020-12-13 13:51

    If using Typescript Vue class components, install the jquery types:

    npm install --save @types/jquery
    

    And declare the directive like this in your Vue file, outside your component:

    Vue.directive('tooltip', function(el, binding) {
        ($(el) as any).tooltip({
               title: binding.value,
               placement: binding.arg,
               trigger: 'hover'             
        })
    });
    

    Then use the sample HTML/bindings from @Ikbel's answer.

    0 讨论(0)
  • 2020-12-13 13:53

    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

    0 讨论(0)
提交回复
热议问题