I'm attempting to utilize a random string (UUID v4) using vue-uuid for existing items and future additions to the list in my to-do list style application. However, I'm uncertain about the correct syntax to use.
After installation, I included it in my project's main.js file:
import UUID from 'vue-uuid';
Vue.use(UUID);
Despite this, I am unsure of how to implement it within my Vue component. Here is what I have attempted:
Template:
<transition-group
name="list"
enter-active-class="animated bounceInUp"
leave-active-class="animated bounceOutDown"
>
<li v-for="item in skills" :key="uuid">{{ item.skill }}</li>
</transition-group>
Script:
import { uuid } from 'vue-uuid';
export default {
name: 'Skills',
data() {
return {
uuid: uuid.v4(),
skill: '',
skills: [{ skill: 'Vue.js' }, { skill: 'React' }]
};
},
};
When using the :key="uuid"
, an error arises stating
Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive (vue/valid-v-for)
. I also tried changing it to :key="item.uuid"
which resolves the error but causes the list not to display.
project repository (built upon this Udemy Vue crash course)