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>

本文作者:CNPolaris

本文链接:https://www.cnblogs.com/cnpolaris/p/14723517.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   CNPolaris  阅读(2996)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起