1

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

1 Answer 1

1

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)
      }
    }
  })
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.