I'm trying to optimize references on a greenfield project that uses Vue.js. It also uses Bootstrap, with requires jQuery for some of its magic, so jQuery is already in the mix. While I have no intention of using its DOM manipulation tools, jQuery is already there, so is there a good reason to not just use it for the AJAX calls from within my Vue components? The syntax between jQuery and axios is fairly similar, so if I can avoid adding another library, that would be groovy.
The reasons behind the "don't use jQuery for AJAX in Vue" mantra are:
$
is already available in the component, it's more tempting to query or manipulate the DOM instead of using v-model
, v-if
, :class
, etc..My recommendation is to write a simple api.js
helper file with methods such as:
api.get(url)
api.post(url, data)
...etc.
These methods may use $.ajax
internally, but when you'll upgrade to Bootstrap 5 (which doesn't require jQuery) you can change the implementation to something else.
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