鲸灵开发-前端开发纪录
前提
项目:低代码产品鲸灵开发
Github地址:xiaojunnanya/whaleDev: 低代码产品 (github.com)
技术栈react
react版本:@18.2
node版本:@16.16.0
开发纪录
vite解决跨域
// vite.config.ts
export default defineConfig({
...
server:{
host:'localhost',
port:5173,
open: false,
proxy: {
'/api': {
target: 'http://localhost:3001',
changeOrigin: true,
rewrite: (path) => path.replace('/api', '')
}
}
}
})
捕获网络错误
在axios封装中,通过promise.reject抛出异常
// 响应拦截器
this.instance.interceptors.response.use((res)=>{
return res.data
},(error) =>{
Promise.reject(error)
})
在代码中监听(当Promise被 reject 且没有 reject 处理器的时候,会触发 unhandledrejection
事件)
window.addEventListener('unhandledrejection', catchErr)