Reputation: 11
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
Upvotes: 1
Views: 715
Reputation: 32921
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)
}
}
})
Upvotes: 1