Hacker News new | ask | show | jobs
by sametmax 3146 days ago
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.

2 comments

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.