我的 React 應用程序成功顯示按鈕,但收到此錯誤。index.js:1const uuidv4 = require('uuid/v4');從 [email protected] 開始,不推薦使用需要 like 的深度。使用 Node.js CommonJS 模塊時請要求頂級模塊或捆綁瀏覽器時使用 ECMAScript 模塊import React, { Component } from 'react';import { Container, ListGroup, ListGroupItem, Button } from 'reactstrap';import { CSSTransition, TransitionGroup } from 'react-transition-group';import uuid from 'uuid/v4';class ShoppingList extends Component { state = { items: [ { id: uuid(), name: 'Eggs' }, { id: uuid(), name: 'Milk' }, { id: uuid(), name: 'Steak' }, { id: uuid(), name: 'Water' }, ] } render() { const { items } = this.state; return ( <Container> <Button color="dark" style={{marginBottom: '2rem'}} onClick={() => { const name = prompt('Enter Item'); if (name) { this.setState(state => ({ items: [...state.items, { id: uuid(), name }] })); } }} >Add Item</Button> </Container> ); }}export default ShoppingList;我嘗試使用 'import { v4 as uuidv4 } from 'uuid';uuidv4();'但是我的按鈕不會出現,我會得到錯誤:未捕獲的 ReferenceError:未定義 uuid也許我應該得到這個錯誤?目前一切正常嗎?
React:從 uuid 開始不推薦使用深度要求,請要求頂級模塊
慕碼人8056858
2022-05-22 16:01:45