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>
posted @ 2021-04-30 22:46  CNPolaris  阅读(2988)  评论(0编辑  收藏  举报