Hacker News new | ask | show | jobs
by lucisferre 3146 days ago
I would strongly disagree that it is ok to use jQuery with Vue. I mean sure, it's ok in that most of the time it isn't going to hurt or break anything, at least if you are just using it to query elements from the DOM.

However, I would argue that is not ok in that it should never be necessary and it's use would be a code smell to me and indicate that the code in question is likely not using Vue properly.

I suspect it would be more valuable in the long term to ask people to take more time and learn to use Vue instead of jQuery to solve the problem at hand.

Edit: I should note that Gitlab came to the same conclusion and I misread their comments on it as accepting the argument that it would be ok for querying the DOM. What the article says:

> At first I had several discussions about using jQuery with Vue. Some had said it might be OK, but only in read-only (querying) situations. However, after doing the research, we found that it is not a good idea to use jQuery with Vue. There will always be a better solution. We found that if you ever find yourself needing to query to DOM within a Vue architecture, then you are doing something wrong.

This I completely agree with.

3 comments

Vue and jquery works ok together.

First, you can gradualy migrate from jquery dom to vue. As both are very light, having both is not bloated.

Plus, you need something to do ajax anyway, and if your site uses it, why add axios as well?

Actually I'd say that vue is probably the best tech if you want to progressively improve a legacy jquery heavy website instead of doing a complete rewrite.

Looks like I misread. They ultimately reached the conclusion that using jQuery was not ok. Good for them.

I would argue as well that AJAX requests don't belong inside Vue components. They belong in services and those services should ideally be behind the Vuex store, but there is nothing wrong with not using Vuex.

If we were just talking about using jQuery for AJAX given that you already were using it, then sure that's fine, use it instead of adding something else like axios. From the article what was being proposed was using it to query the DOM. There is no use case for that with Vue.

Isn't fetch widespread enough to use these days?
Only if you want to ignore 12% market share or use a polyfill:

https://caniuse.com/#search=fetch https://www.netmarketshare.com/browser-market-share.aspx?qpr...

Plus, although fetch is tremendously better than XMLHttpRequest, it still has quirks. It doesn't send cookies by default. The promise resolve on success on code 400 and 500. Headers are verbose. You have to encode and decode json manually. You have to force CORS for it to work.

The end of this article show you the problem:

https://medium.com/@shahata/why-i-wont-be-using-fetch-api-in...

Eventually you end up writting code to wrap fetch. So why not just use jquery or axios ? It's already documented and tested.

AFAIK, their old codebase was full of jQuery and they are replacing some parts with Vue, hence they use both. They might not have used jQuery at all if they were starting from scratch.
Perhaps not, but there is no reason to use jQuery within the Vue components. Doing so now means that it is basically there to stay. That may be acceptable, but it is definitely unnecessary.
> However, after doing the research, we found that it is not a good idea to use jQuery with Vue

I have a hard time taking seriously the opinion of someone who bases their sweeping global assertions on "research" and not on actual experience.

The only time I needed jquery was when I was using bootstrap, and that was easily solved by ditching bootstrap and going with bluma.