Recent Posts

banner-top-it-job-right.gif

Archive

Tags

Related Posts

Basic steps help you use jQuery Plugin like a Pro

It is not a better initiative to use jQuery and Vuejs in the UI. Do not get it if you might prevent it. However, you want to read this not because you use jQuery and Vue together, but since you get to. Maybe the customer is claiming about using the specific jQuery plugin or code which you will not get time and tech tips to write for Vue again.

Basic steps help you use jQuery Plugin like a Pro
Basic steps help you use jQuery Plugin like a Pro

The trouble between taking jQuery and Vue


1. Why is making this particularly hazardous?

Vue is a fantastic library in the circumstance in which you have to make it entirely possess the DOM’s patch which you provide it (identified by what you pass to e1). If jQuery takes a transformation to the element which Vue is controlling, adds a perfect class to something, Vue will not be aware of the transformation and is going to move right towards and overwrite it in the following update cycle.


2. Method: Take a component like a wrapper

Understanding that jQuery and Vue are not going to share components of the DOM, we need to claim Vue to cordon off the zone and offer it over to jQuery.

Taking a component to wrap the jQuery plugin feels like the solution to move since:

- We might take the component interface to link with the Vue application’s rest through events or props.

- Components might opt-out for updates with V-once.

Method: Take a component like the wrapper
Figure 1. Creating Wrapper Components

3. Install jQuery UI date picker

In reality, you want to contain either the jQuery or jQuery UI libraries in the campaign initially. When you get those, the date picker just requests an input element to attach its own to:

It might be instantiated by choosing it and calling the technique.


4. Datepicker component

To create the date picker component, the template might be the one input factor.

Warnings: this component might be nothing other than the wrapper for the plugin. Do not push the fortune and offer it any data attributes or take the slots.

Datepicker component
Figure 2. A date picker component for VueJs

5. Instantiating widget

Instead of providing the input, the ID, and choosing it, we might take this.$e1, as each component might access its root node like that. The root node will be definitely the input.

We might wrap the node reference in the jQuery selector to get access to the datepicker method i.e $(this.$e1).datepicker().

Highlight that we take the mounted lifecycle hook-like this.$e1 is not defined till the component is mounted.

Instantiating widget
Figure 3. Use “Mounted” lifecycle

6. Teardown

To teardown the date picker, we might surf the same approach and take the lifecycle hook. Remember that we have to use before destroy to guarantee our input is even in the DOM and therefore might be chosen (it is not defined in the destroy hook).


7. Pass config with props

To re-use the component, it might be pretty to permit for adjustable configuration, such as identifying the date format for configuration attribute dateFormat. We might do it with props by self-learning.


Final thoughts

Here are some fundamental steps and tech skills which assist you in using the jQuery plugin like an expert so far. Lastly, we hope that you can reply to us by putting your comments below. Thanks!

Source: Internet


Đọc thêm: What Is The Difference Between Ai, Data Science, And Machine Learning?

-------------------------------


JT1 - IT Recruitment Agency


Website: https://www.jt1.vn


Email: hi@jt1.vn