Problems and Solutions
This may cause an update error
This error indicates that in your V-for
loop, key
The value may be duplicate.
Duplicate key
will cause rendering errors.
The reason for the error is that I didn’t add the key
attribute at the beginning. The error code fragment is as follows:
<template>
<vue-aplayer
:audio="audio"
:lrc-type="3"
:fixed='fixed'
:autoplay='autoplay'
:order='order'
:volume='volume'
:theme='theme'
:listFolded='listFolded '
/>
</template>
No more errors will be reported after adding key
<template>
<vue-aplayer
:audio="audio"
:lrc-type="3"
:fixed='fixed'
:autoplay='autoplay'
:order='order'
:volume='volume'
:theme='theme'
:listFolded='listFolded '
:key="audio.name"
/>
</template>
Note:
audio
attribute is the list I want to traverse, andname
is the primary key in my list, so here I takeaudio. Name
as the value ofkey
, key must be unique.
Official description
key
Expectation: the special attributes of number | string
key
are mainly used in Vue’s virtual DOM algorithm to identify vnodes when comparing old and new nodes. If you do not use keys, Vue will use an algorithm that minimizes dynamic elements and tries to modify/reuse elements of the same type in place as much as possible. When using a key, it rearranges the order of elements based on the change of the key, and removes elements that do not exist in the key. Child elements with the same parent element must have a unique key. Duplicate keys can cause rendering errors. The most common use case is the combination of V-for
:
<ul>
<li v-for="item in items" :key="item.id">...</li>
</ul>
It can also be used to force replacement of elements/components rather than reuse it. It may be useful when you encounter the following scenarios:
Completely trigger the life cycle hook of the component to trigger the transition, for example:
<transition>
<span :key="text">{{ text }}</span>
</transition>
When text
changes, <span>
is always replaced rather than modified, so a transition is triggered.
Read More:
- Vue Error: [Vue warn]: Duplicate keys detected
- Error: Duplicate plugin/preset detected [How to Solve]
- [Solved] Error: this may cause an update error. (“prov”, value)
- [Solved] Vue Startup Error: Emitted value instead of an instance of Error
- [Solved] Vue Error: Parsing error: No Babel config file detected for
- [Solved] Vue Error: Parsing error:No Babel config file detected for xxx
- [Solved] Vue Error: Parsing error: No Babel config file detected for /Users/Usename/xxx…
- [Solved] Vue Element Date plug-in reports an error in form validation
- [Solved] React Dependency Error: Invalid tag name “^np.0.2“ of package “react@^np.0.2“: Tags may not have an
- Vue installs sass loader directly, and node sass reports an error
- [Solved] vue3vite Error: Failed to resolve import “@vue/server-renderer from “src\App.vue“. Does the file exist
- The toast light prompt of vant in Vue reports an error
- After Vue is packaged to the server, the static resource path reports an error
- Solve the problem of repeatedly clicking the same route console in Vue to report an error
- [Solved] Vue Error: Uncaught TypeError: Vue.createApp is not a function
- Full screen scrolling by Vue + Vue awesomeswiper
- NPM run dev runs the Vue project and reports an error: Node Sass does not yet support your current environment
- [Solved] VUE D:\project\vueProject\vue-02\src\components\hello.vue 5:5 error Parsing error: x-invalid-end-tag
- Vue warn]: vue3 element Component emit Pass Event Error
- Vue2.0: How to Use vue3 api to encapsulate Axios