类型错误:无法读取未定义的属性“v4”

问题描述 投票:0回答:2

我在 Vue.js 中遇到此错误:

vue.esm.js?efeb:628 [Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'v4'
of undefined"

found in

---> <AddTodo> at src/components/AddTodo.vue
   <App> at src/App.vue
     <Root>

我已经安装了 uuid,所以 v4 应该可以工作,但事实并非如此。

javascript vue.js vue-component typeerror uuid
2个回答
22
投票

我遇到了同样的错误,我解决了它。

import {v4} from 'uuid';

const uuId = v4()

9
投票

用途:

import * as uuid from 'uuid';

现在您可以从 uuid 调用任何内容。比如,

uuid.v4();
© www.soinside.com 2019 - 2024. All rights reserved.