56 lines
1.4 KiB
Markdown
56 lines
1.4 KiB
Markdown
|
|
# 前端开发已知问题和解决方案
|
|||
|
|
|
|||
|
|
## 1. antd-mobile-icons 导入错误
|
|||
|
|
|
|||
|
|
**问题**: `The requested module '/node_modules/.vite/deps/antd-mobile-icons.js' does not provide an export named 'PlusOutline'`
|
|||
|
|
|
|||
|
|
**原因**: antd-mobile-icons 中没有 `PlusOutline` 图标
|
|||
|
|
|
|||
|
|
**解决方案**: 使用正确的图标名称:
|
|||
|
|
- `PlusOutline` → `AddOutline`
|
|||
|
|
- 可通过查看 `node_modules/antd-mobile-icons/es/index.d.ts` 确认可用的图标
|
|||
|
|
|
|||
|
|
## 2. DatePicker 组件报错
|
|||
|
|
|
|||
|
|
**问题**: `Cannot read properties of null (reading 'getTime')`
|
|||
|
|
|
|||
|
|
**原因**: DatePicker 组件的 `min` 或 `max` 属性接收到了 `null` 值
|
|||
|
|
|
|||
|
|
**解决方案**: 使用条件展开运算符,只在值存在时传递属性:
|
|||
|
|
```tsx
|
|||
|
|
// 错误写法
|
|||
|
|
<DatePicker min={startDate || undefined} />
|
|||
|
|
|
|||
|
|
// 正确写法
|
|||
|
|
<DatePicker {...(startDate && { min: startDate })} />
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 3. 端口占用问题
|
|||
|
|
|
|||
|
|
**问题**: Vite 启动时端口被占用,自动尝试其他端口
|
|||
|
|
|
|||
|
|
**解决方案**: 清理旧进程后重启
|
|||
|
|
```bash
|
|||
|
|
ps aux | grep vite | grep -v grep | awk '{print $2}' | xargs -r kill -9
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 4. 防火墙规则
|
|||
|
|
|
|||
|
|
**问题**: 外网无法访问开发服务器
|
|||
|
|
|
|||
|
|
**解决方案**: 添加防火墙规则
|
|||
|
|
```bash
|
|||
|
|
iptables -I INPUT -p tcp --dport 5173 -j ACCEPT
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 5. Vite 配置
|
|||
|
|
|
|||
|
|
确保 `vite.config.ts` 中配置正确的 host:
|
|||
|
|
```ts
|
|||
|
|
server: {
|
|||
|
|
port: 5173,
|
|||
|
|
host: '0.0.0.0', // 允许外网访问
|
|||
|
|
proxy: { ... }
|
|||
|
|
}
|
|||
|
|
```
|