[Vuejs]-Using jQuery plugin in Vue.js single file component

0👍

Solution: use a component as a wrapper

Check out the tutorial here:
https://vuejsdevelopers.com/2017/05/20/vue-js-safely-jquery-plugin/

0👍

Check the order of js files/script inside your html. It’s possible that the Vue script is executed before jQuery is loaded. Move jQuery-related script tags above Vue script tags. You can also safely check if jQuery is available in your Vue script by checking for existence of window.$:

if (typeof window.$ === 'function') {
  $("#autocomplete").autocomplete({
        source: [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ]
    });
}
👤blaz

-1👍

I would suggest u not to use Jquery in Vue. Its bad practice. There is a number of vue plugins u can use and even create your own (which is best option IMHO)

https://www.npmjs.com/package/vue2-autocomplete-js
https://github.com/paliari/v-autocomplete
https://vuejsexamples.com/tag/autocomplete/
https://alligator.io/vuejs/vue-autocomplete-component/

Leave a comment