Vuejs error, Invalid prop: type check failed for prop. Expected Date, got Number with value

ILovePHP

I have a very simple code that was supposed to get me started on learning Vue but I somehow still managed to bug it. I have the following code:

export default {
  name: 'my-component',
  data() {
      return {
          model: this.value,
          dateConfig: {
              format: 'DD-MM-YYYY',
              useCurrent: true,
              firstDate: this.minDate,
              secondDate: this.maxDate
          },
      }
  },
  props: {
    firstDate: {type: Date, required: false},
    secondDate: {type: Date, required: false}
  }
}

And after importing this file and trying to use it in another page as follows:

<my-component v-bind:first-date="12-12-2019" v-bind:second-date="31-11-2011"></my-component>

This returns the following two errors:

Invalid prop: type check failed for prop "firstDate". Expected Date, got Number with value -2019.

and

Invalid prop: type check failed for prop "secondDate". Expected Date, got Number with value -1991.

While the first error makes a bit of sense (even though I don't know why it is happening), the second error shocks me as I don't have '1991' anywhere. Could someone please explain to me why this is happening as I adhered to the format the date should be in?

17axaH

This is because you pass in an expression in props javascript. From your example: 11 - 31 - 2011 === -1991.

I recommend reading the documentation for understanding props: https://vuejs.org/v2/guide/components-props.html#Passing-Static-or-Dynamic-Props

You can fix it as follows:

<my-component
  v-bind:first-date="new Date('12-12-2019')"
  v-bind:second-date="new Date('31-11-2011')"
></my-component>

But I would pass the data as a string. But in such cases, do not forget to change the type of the passed parameter in the component. «Date» change to «String».

I hope I helped you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

[Vue warn]: Invalid prop: type check failed for prop "page". Expected Number with value 0, got String with value ""

VueJs - Invalid prop: type check failed for prop "page". Expected DocumentPageDto, got Object

Invalid prop: type check failed for prop "value". Expected Boolean, got String with value "0"

Invalid prop: type check failed for prop "cellClass". Expected String with value "[object Object]", got Object

[Vue warn]: Invalid prop: type check failed for prop "productCartData". Expected Object, got String with value "[object Object]"

vue warning: Invalid prop: type check failed for prop "modalState". Expected Boolean, got Function

Invalid prop: type check failed for prop "items". Expected Array, got String

Invalid prop: type check failed for prop "data". Expected Array, got Object

Vue.js - Invalid prop: type check failed for prop "src". Expected String, Object, got Promise

How to pass ref as prop: [Vue warn]: Invalid prop: type check failed for prop "containerRef". Expected Object, got HTMLDivElement?

Warning: Failed prop type: Invalid prop `value` of type `number` supplied to `TextInput`, expected `string`

Failed prop type: Invalid prop `value` of type `number`

Vue 3 Typescript props: [Vue warn]: Invalid prop: type check failed for prop "organisation". Expected Null | Boolean, got Object

VueJs: Invalid prop:Expected Boolean, got Undefined

Invalid prop type from router params, expected Number got String

Failed prop type: Invalid prop 'value'

vue.js vuetify test-utils warning : Vue warn]: Invalid prop: type check failed for prop "src". Expected String, got Object

GETTING ERROR : Warning: Failed prop type: Invalid prop `children` supplied to `Form`, expected a ReactNode

React router error (Failed prop type: Invalid prop `children` supplied to `Switch`, expected a ReactNode.)

laravel vue pagination return invalid prop type check failed for prop

Image not displaying when using Graphql and Contentful in Gatsby, Failed prop type: Invalid prop `image` of type `number` expected `object`?

Failed prop type: Invalid prop `to` supplied to `Redirect`

Warning: Failed propType: Invalid prop of type `array` expected `object` with React

Failed prop type: Invalid prop `match.params` of type `object` supplied to `Page`, expected `string`

Warning: Failed prop type: Invalid prop `data` of type `object` supplied to `Carousel`, expected `array`

Failed prop type: Invalid prop `onClick` of type `object` supplied to `ButtonBase`, expected `function`

Failed prop type: Invalid prop of type `function` supplied expected a single ReactElement

Failed prop type: Invalid prop `onClick` of type `object` supplied to `Button`, expected `function`

Why do I get Failed prop type: Invalid prop `onAnimationFinish` of type `object` supplied to `LottieView`, expected a `funtion`