vue.runtime.esm.js:4605 [Vue warn]: Avoid using non-primitive value as key, use string/number value instead.
时间: 2024-03-28 19:41:39 浏览: 284
This warning message is usually triggered when you use a non-primitive value (such as an object or an array) as a key in a Vue.js template. Vue.js recommends that you use string or number values as keys instead.
You can fix this warning by converting your non-primitive value to a string or a number and using that as the key. For example, if you have an object named `myObject`, you can convert it to a string using `JSON.stringify(myObject)` and use that as the key.
Here's an example of how you can fix this warning in a Vue.js template:
```
<template>
<div v-for="(item, index) in items" :key="JSON.stringify(item)">
{{ item.name }}
</div>
</template>
```
In this example, we're using `JSON.stringify(item)` as the key instead of `item` itself. This ensures that the key is a string and prevents the warning from being triggered.
阅读全文