简体   繁体   中英

Using jquery plugin with vuejs, without webpack?

I am having trouble figuring out how to use a jquery plugin within a vue component. I am not using webkit, browserify, or ES2016. Is there still a way for me to be able to use a plugin and target an element within the template tag? Google has yielded no results that were helpful.. the plugin in question is jquery.payment for stripe

You can use the plugin in the ready event of your component. In short it would look something like this:

new Vue({
  el: '#app',
  ready: function() {
    jQuery('.find-thing').payment('formatCardNumber')
  }
})

Here's how I'd approach it if I had no other option. I did not test it but it should be relatively close:

<div id="app">
  <input class="payment-input" v-model="creditCardNumber">
  <div v-if="!creditCardNumberValid">BAD CC</div>
</div>

<script>
  new Vue({
    el: '#app',
    data: {
      creditCardNumber: '',
    },
    ready: function () {
      var paymentInput = this.$el.querySelector('.payment-input');
      jQuery(paymentInput).payment('formatCardNumber')
    },
    computed: {
      creditCardNumberValid: function () {
        return jQuery.payment.validateCardNumber(this.creditCardNumber)
      }
    }
  })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM