当前位置: 首页 > article >正文

vue3 + ts项目(无vite)报错记录

记录项目创建后遇到的报错
1.类型“Window & typeof globalThis”上不存在属性“_CONFIG”。ts(2339)

问题描述:

使用全局 window 上自定义的属性,TypeScript 会报属性不存在
在这里插入图片描述

解决:需要将自定义变量扩展到全局 window 上,在项目的xxx.d.ts文件添加如下代码声明

declare interface Window {
  _CONFIG: any
}

添加后好像得重启编译器

2.axios报错
2.1 问题描述:

在这里插入图片描述
这个报错是因为axios版本更新后出现了新的类型导致的问题,可以根据此贴中的描述来解决,也可以用回旧版本解决,我是用回了0.21.x的旧版本

yarn add axios@^0.21.1
2.2 类型“AxiosResponse”上不存在属性“success”。ts(2339)

在这里插入图片描述

解决:封装文件中追加声明描述

import axios, { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios'

declare module "axios" {
  interface AxiosResponse<T = any> {
    result:any
    success:any,
    // 这里追加你的参数
  }
  export function create(config?: AxiosRequestConfig): AxiosInstance;
}
3.vue.config.js路径别名配置
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  publicPath: "/",
  outputDir: "dist",
  chainWebpack: config => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('@assets', resolve('src/assets'))
      .set('@views', resolve('src/views'))
      .set('@comp', resolve('src/components'))
  }
});
4.项目引入第三方库的关键字报错

问题描述:
在这里插入图片描述
这里就是第三方库的关键字DC报错了

解决:还是在xxx.d.ts文件中追加关键字声明

declare var DC: any

http://www.kler.cn/a/132268.html

相关文章:

  • react-router-dom 版本6.18.0中NavLink的api和属性介绍
  • Redis篇---第六篇
  • 【Linux】常用系统工作命令
  • 大数据架构Lambda-架构师(六十九)
  • [C/C++]数据结构 链表OJ题:随机链表的复制
  • ES6 导入导出
  • redis运维(九)字符串(二)字符串过期时间
  • 为什么C++标准库中atomic shared_ptr不是lockfree实现?
  • 填充每个节点的下一个右侧节点指针
  • wpf devexpress Property Grid创建属性定义
  • Oracle OCP / MySQL OCP认证容易通过吗
  • es 算法函数 有点不太懂了没有大神给指点一下
  • 【2】SM2验签工具和RSA验签工具
  • 【漏洞复现】IP-guard WebServer 远程命令执行
  • element el-date-picker报错Prop being mutated:“placement“快速解决方式
  • rviz是如何获取图像里选择的点云的3D坐标的
  • vue3 - pinia 中的 storeToRefs
  • 五、函数的介绍
  • 大数据毕业设计选题推荐-机房信息大数据平台-Hadoop-Spark-Hive
  • 初识MongoDB及安装