vue-cli3引入uuid

      首先安装就不多说了。

npm install --save uuid

      uuid不需要在main.js中做配置,在需要使用的vue页面引入即可。
      但是我原先使用uuid的时候(使用的VScode),直接在

import uuid from "uuid"

      即可,下面直接使用uuid.v4()即可。
      但是近期在使用uuid的时候(改为了HbuilderX),用以上的方式,在编译时就报错:

warning: "export 'default' (imported as 'uuid') was not found in 'uuid'

      原因还不知道是为什么,但是已经找到了解决方法,就是不再import,而是以常量的方式声明uuid:

const uuid = require('uuid')

      这样编译就不会出错了,下面的使用方式还一样,直接uuid.v4()

猜你喜欢

转载自blog.csdn.net/weixin_42822484/article/details/106537921