uuidv4生成不了?
来源:14-9 flyBox 组件 uuid 改造 + 实现过程回顾

他门说这就是人生
2020-08-06
老师,不知道为什么,这个UUID库生成不了UUID,我的代码如下:
import {ref, onMounted, computed, getCurrentInstance} from 'vue' import { v4 as uuidv4 } from 'uuid' export default { name: 'flyBox', setup() { const uuid = uuidv4() let width = ref(0) let height = ref(0) let path = computed(() => `M5 5 L${width.value - 5} 5 L${width.value - 5} ${height.value - 5} L5 ${height.value - 5} Z`) onMounted(() => { const instance = getCurrentInstance() width.value = instance.ctx.$refs.container.clientWidth height.value = instance.ctx.$refs.container.clientHeight }) return { path, uuid } } }
报错如下:
TypeError: crypto.randomFillSync is not a function
ps:
我的版本已经和老师的一致了。8.2.0,还是生成不了。
ps(2020-08-14):
> data-visual-ui@1.0.1 build:dev D:\proj\src\learning\data-visual-ui > eslint ./src && rollup -c rollup.config.dev.js D:\proj\src\learning\data-visual-ui\src → dist\jingsi.data-visual.js, dist\jingsi.data-visual.es.js... (!) Plugin node-resolve: preferring built-in module 'crypto' over local alternative at 'crypto', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning (!) Unresolved dependencies https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency crypto (imported by node_modules\_uuid@8.3.0@uuid\dist\esm-node\md5.js, node_modules\_uuid@8.3.0@uuid\dist\esm-node\sha1.js, node_modules\_uuid@8.3.0@uuid\dist\esm-node\rng.js) (!) Missing global variable name Use output.globals to specify browser global variable names corresponding to external modules crypto (guessing 'crypto') created dist\jingsi.data-visual.js, dist\jingsi.data-visual.es.js in 1.2s
写回答
1回答
-
扬_灵
2020-08-06
同学你好,crypto模块的主要功能是加密解密,会在打包资源文件中自动导入并使用,你把项目代码上处一下,我在本地帮你定位一下问题吧072024-03-25
相似问题