HerringtonDarkholme / av-ts

A modern, type-safe, idiomatic Vue binding library
MIT License
216 stars 11 forks source link

howto no data props - question #55

Closed Jacknq closed 7 years ago

Jacknq commented 7 years ago

hi, lets say I want to use some lib that comes with regular vue like validation (vuelidate) which extends vue and its outside of data. How to simulate same behavior on your component, if its prop or data its not found.

export default {
  data () {
    return {
      name: '',
      age: 0
    }
  },
  validations: {
    name: {
      required,
      minLength: minLength(4)
    },
    age: {
      between: between(20, 30)
    }
  }
}

https://monterail.github.io/vuelidate/#sub-basic-form

HerringtonDarkholme commented 7 years ago

You need to roll out your own decorator. Otherwise, you can just put validations in @Component({validattions: {}})

Jacknq commented 7 years ago

im in av-ts 6.3 last compatible with kilimanjaro If I put it in component I get:

 error TS2345: Argument of type '{ validations: { username: { required: any; minLength: any; }; }; }' is not assignable to param
eter of type 'ComponentOptions<Vue>'.
  Object literal may only specify known properties, and 'validations' does not exist in type 'ComponentOptions<Vue>'.
 @Component({
    validations: {
    username: {
      required,
      minLength: minLength(4)
    }
  }
    })
HerringtonDarkholme commented 7 years ago

You need to extend vue's ComponentOption type.

https://github.com/HerringtonDarkholme/av-ts/wiki/FAQ#3-componentmeta-augmentation

Jacknq commented 7 years ago

ok, Thanks.