v-credit-card icon indicating copy to clipboard operation
v-credit-card copied to clipboard

@change not working

Open sdwru opened this issue 4 years ago • 1 comments

For some reason @change is not working. If I leave everything else the same and change it to @cardChanged it starts working on console.log showing the card type as soon as I start typing in numbers. So it's just @change that doesn't work. I don't see any errors in the chrome developer console or vue console.

I tried registering globally and locally.

 npm list vue

+-- [email protected]
+-- [email protected]
| `-- [email protected]
|   `-- [email protected]  deduped
+-- [email protected]
| `-- [email protected]
+-- [email protected]
| `-- [email protected]  deduped
+-- [email protected]
| `-- [email protected]  deduped
+-- [email protected]
| `-- [email protected]  deduped
+-- [email protected]
| `-- [email protected]  deduped
`-- [email protected]
  `-- [email protected]  deduped
npm info v-credit-card

[email protected] | MIT | deps: 2 | versions: 14
Beautiful credit card form component for vueJS

I am running npm run serve for http access.

I tried going into the compiled dist code and adding console.log to the computed and watcher function. Neither of them appear to fire.

computed: {
     fields: function fields() {
         console.log('computed fields() fired');
         return [this.form.name, this.form.cardNumber, this.form.expiration, this.form.security].join('');
     }
...
...
watch: {
    fields: function fields() {
      console.log('@change emitter fired');
      this.$emit('change', Object.assign({}, this.$data.form));
    }

sdwru avatar Jun 01 '20 21:06 sdwru

Yup, is true. I ran into the same issue. The solution I found was to watch directly the form with the card data usign the "deep" property like this: form: { deep:true, handler: function handler(newV, oldV) { this.$emit('dataChanged', newV); } } just add it to your VCreditCard.ums.js and VCreditCard.common.js files within the watch property, and now listen to the dataChanged event like you normally do, <VCreditCard @dataChanged="dataChange"/>, you can now define the dataChange method within the parent component and do whatever you need with your data.

Hope it helps!

hugomejia avatar Aug 01 '20 10:08 hugomejia