Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VUEJS - Why do I get: Uncaught TypeError: Right-hand side of 'instanceof'?

I am facing issue in vue.js about "Uncaught TypeError: Right-hand side of 'instanceof' is not an object".

I am using Vue 2.2.1 version following is my code snippet where I am getting this issue.

Vue.component('componentName', {
'template': ``,
 props: {
  contentTypeUid: {
    type: 'string',
    required: false
  },
  limit: {
    type: 'number',
    required: false,
    default: 10
  }
 },
 ......
});

While if instead of above following working without any issue, but I want to use above format as I need to specify some validations and default values on props.

Vue.component('componentName', {
'template': ``,
 props: ["contentTypeUid", "limit"],
 ......
});

Thanks.

like image 699
HDB Avatar asked Oct 17 '18 10:10

HDB


People also ask

What is type error in VUE JS?

Types of errors js app: Syntax errors occur when you use the wrong syntax. Runtime errors are caused by illegal operations during execution. Logical errors are difficult to identify because they result from mistakes in the program logic. HTTP errors are common when you're working with APIs.

What is $El in Vue?

The $el option in Vue provides Vue with an existing HTML element to mount the Vue instance generated using the new keyword. this. $el. querySelector is used to access HTML elements and modify the element's properties.

What does $t mean in Vue?

Vuex is a state management pattern for vue. js. $t is the injected method from vue. js or Vue. i18n.

What is $V in Vue?

$v is an object that calls vuelidate (at the time of writing the comment, supported in version Vue. js 2.0), which is intended to check every input, which is made in a non-html form.


2 Answers

Use:

props: {
  contentTypeUid: {
    type: String, // not 'string'
    required: false
  },
  limit: {
    type: Number, // not 'number'
    required: false,
    default: 10
  }
 },
like image 198
Юра Панарин Avatar answered Oct 14 '22 00:10

Юра Панарин


In my case, it was a component property that had a null type:

props: {
    role:{
      type: [String, null],
      required: true
    },

changing it to

props: {
   role:{
      type: String,
      required: true
   },

And making sure, that the component always gets a string, fixed the issue. I guess the combination of required and a possible null value was not very good...

like image 2
nihils Avatar answered Oct 13 '22 23:10

nihils