Vue中生成UUID
<template>
<div :id="elId" class="container">
<a>{{elId}}</a>
<div>
<button @click="createUUID()">shuaxun</button>
</div>
</div>
</template>
<script>
import {v4} from 'uuid' // npm install -S uuid
export default {
data () {
return {
elId: ''
}
},
created(){
this.elId = v4() // 避免key重复
},
methods: {
createUUID() {
const temp = v4()
this.elId = temp
}
}
}
</script>