Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model binding breaks when using jQuery <1.7 #2199

Closed
rjv opened this issue Jan 20, 2016 · 3 comments
Closed

Model binding breaks when using jQuery <1.7 #2199

rjv opened this issue Jan 20, 2016 · 3 comments

Comments

@rjv
Copy link

rjv commented Jan 20, 2016

If jQuery is being used on the same page as Vue, it appears that Vue has a dependency on jQuery 1.7 or above. The reason for the dependency is illustrated here (from the Vue source http://vuejs.org/js/vue.js):

this.hasjQuery = typeof jQuery === 'function';
    if (this.hasjQuery) {
      jQuery(el).on('change', this.listener);
      if (!lazy) {
        jQuery(el).on('input', this.listener);
      }
    } else {
      this.on('change', this.listener);
      if (!lazy) {
        this.on('input', this.listener);
    }
}

This code makes the assumption that if jQuery is available, then the jQuery.on method is also available. According to the jQuery API, this method was first introduced in 1.7 (http://api.jquery.com/on/).

Here's an example of the scenario I'm describing: https://jsbin.com/darawa/edit?html,js,console,output

You can see that we get an error because we're using jQuery 1.6.4.

I'm not sure if it's reasonable to make the assumption that the included jQuery has the on method available (e.g. they're using 1.7 or newer). I realize 1.7 is quite old, but at the very least I think we could handle this scenario more gracefully.

@young-steveo
Copy link

I dunno if I agree with adding support for jQuery < 1.7. That version is already over 4 years old (as you mentioned). Since there are very few BC breaks between 1.6 and 1.7, it should be reasonable to upgrade the jQuery version in any project using VueJS (or, just go without jQuery at all, if that's possible).

@rjv
Copy link
Author

rjv commented Jan 20, 2016

I encountered this scenario the other day when I was tasked to introduce a new feature into an existing legacy system. That legacy system was working with jQuery 1.5.x, and it was dependent on jQuery.live, so I couldn't upgrade to the more modern versions. While it's true that upgrading to 1.7 could remedy the issue, I may encounter situations where I have no control over what version the legacy system includes.

@young-steveo mentions that you should go without jQuery completely if it's possible. As described in my situation, it was beyond my control. I'm not necessarily advocating that Vue should support legacy versions of jQuery, but since Vue works just fine without jQuery, I feel that it should fail gracefully if jQuery exists and jQuery.on does not. I think the conditional should check for both; not just whether jQuery exists.

@young-steveo
Copy link

@rjv Ah, so you're saying it should just not use jQuery if jQuery.on is undefined? I could see that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants