A decimal variable in data of vuejs component

Viewed 321

We don't have the decimal type between the possible types to use in the data of a vuejs component (String, Number, Boolean, Array, Object, Date, Function, Symbol), so how to define a variable of this type ?

1 Answers

A decimal variable is of type Number, you could define it as number then use a validator to check if it's decimal :

props:{
 price:{
   type:Number,
   validator(value){
     return value%1!==0
  }
 }
}
Related