Why Invalid prop: type check failed for prop "value". Expected String, Number, Object, Boolean, got Array shows for the program below mention?

huangapple go评论61阅读模式
英文:

Why Invalid prop: type check failed for prop "value". Expected String, Number, Object, Boolean, got Array shows for the program below mention?

问题

无效的属性:类型检查失败,期望 String、Number、Object、Boolean,而传入了 Array。在下面提到的程序中显示了这个错误:

html:

<model-select :options="usersAssignData" v-model="userNameData" class="form-control col-sm-4" @keyup.native="getUser">

script:

 getUser(e) { 
       console.log("idd", this.selectedZone)
        var user = e.target.value;
        axios.get("/helpdesk/getUsers", {
        params: {
          q: user,
          account_id: this.selectedZone,
          searchOption: 'username'
        },
          headers: {
            'Authorization': localStorage.getItem('token')
          }
        })
        .then(response => {
          this.usersAssignData = response.data

        })
        .catch(error => {
          reject(error);
          console.log(error);
        });
    }
英文:

Why Invalid prop: type check failed for prop "value". Expected String, Number, Object, Boolean, got Array shows for the program below mention?

html:

&lt;model-select :options=&quot;usersAssignData&quot;  v-model=&quot;userNameData&quot; class=&quot;form-control col-sm-4&quot; @keyup.native=&quot;getUser&quot;  &gt;

script:

 getUser(e) { 
       console.log(&quot;idd&quot;,this.selectedZone)
        var user = e.target.value;
        axios.get(&quot;/helpdesk/getUsers&quot;, {
        params: {
          q: user,
          account_id: this.selectedZone,
          searchOption: &#39;username&#39;
        },
          headers: {
            &#39;Authorization&#39;: localStorage.getItem(&#39;token&#39;)
          }
        })
        .then(response =&gt; {
          this.usersAssignData = response.data

        })
        .catch(error =&gt; {
          reject(error);
          console.log(error);
        });
    }

答案1

得分: 3

usersAssignData属性的类型可能不是一个数组,而axios调用似乎返回了一个数组。尝试按照@DharaParmar所说的方式将属性的类型设置为数组。

英文:

The type of the prop usersAssignData of your component is probably not an Array, and the axios call it seems to be returning an Array. Try doing what @DharaParmar said, setting the type of the prop as an array.

答案2

得分: 2

Sure, here is the translated code:

## 请尝试在要使用您的 props 值的文件中使用以下代码 ##

<script>
    export default {
        props: {
            usersAssignData: {
                type: Array,
                default: () => [],
            },
        }
    }
</script>

I hope this helps! If you have any more code to translate, please feel free to provide it.

英文:

Try using the below code in file which you want to use your props value

&lt;script&gt;
    export default {
        props: {
            usersAssignData: {
                type: Array,
                default: () =&gt; [],
            },
        },
    } 
&lt;/script&gt;

答案3

得分: -1

这对我有效:

data() {
  return {
    usersAssignData: 数组/对象/字符串/数字,
  }
}

现在 usersAssignData 可以是数组、对象、字符串或数字,你不会再看到那个错误了 Why Invalid prop: type check failed for prop "value". Expected String, Number, Object, Boolean, got Array shows for the program below mention?

英文:

hey this works for me:

data() {
  return {
    usersAssignData:Array/Object/String/Number,
  }
}

now usersAssignData can be Array or Object or String Or Number and your not gonna see that error anymore Why Invalid prop: type check failed for prop "value". Expected String, Number, Object, Boolean, got Array shows for the program below mention?

huangapple
  • 本文由 发表于 2020年1月3日 21:01:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579104.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定