1

Vuejs beginner here, so please be patient...

Can anyone tell me what's the best way to use jquery plugins from within my page? Should I wrap it in a directive or in a component? I'm thinking that the component route might be the best option, but I'm still not sure this is the best solution for my problem...

6
  • Do not mix Vue with jQuery. This makes no sense unless your project has been using it before. Vue has plenty of plugins which can replace your jQuery plugins. Commented Jan 29, 2018 at 12:53
  • Hello. That's precisely my scenario. Btw, can you suggest some plugins which let me work in a mixed scenario (asp.net mvc is handling postback while vue is being used to handle some of the operations in the client side) Commented Jan 29, 2018 at 13:05
  • It's really an "it depends" type of question (and too broad to answer generically). Look into components, custom directives and plugins Commented Jan 29, 2018 at 13:45
  • see vuejsdevelopers.com/2017/05/20/vue-js-safely-jquery-plugin Commented Jan 29, 2018 at 13:54
  • Well, I've went with components... There's an example on the official docs, so I've went with it... Commented Jan 29, 2018 at 14:17

1 Answer 1

2

Despite the jQuery hate some people hang on to, my personal opinion, along with many others, is that it's perfectly fine to use jQuery with vue with caveats.

  1. Don't use it for DOM manipulation if at all possible. It's often far simpler to use vue native logic to handle DOM changes, you just need to learn some new stuff.
  2. If you do need to use a jQuery plugin, it might be best to isolate it if possible, in a component.
  3. Sometimes it's just easier to rewrite plugins in a custom component that does the same thing. Some jQuery plugins are pretty simple, look into the code and see if it's easy to port.
  4. See if it's already been ported. Do some searches on NPM or Google, often you'll find that someone else has already done the legwork.

That being said, I would try to wrap it in a component if you can't replace the plugin completely.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.