Mrcdh技术博客 Mrcdh技术博客
首页
  • Html5
  • Javascript
  • Nodejs
  • electron
  • Android
  • 微信公众号
  • 框架
  • 其他
  • Mysql
  • PHP
  • Python
  • java
  • Gulp
  • 其它
  • 网站
  • 资源
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Mrcdh

全栈开发小学生
首页
  • Html5
  • Javascript
  • Nodejs
  • electron
  • Android
  • 微信公众号
  • 框架
  • 其他
  • Mysql
  • PHP
  • Python
  • java
  • Gulp
  • 其它
  • 网站
  • 资源
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • element-ui

  • vue3

    • pinia持久化插件pinia-plugin-persist的使用
    • Vue3项目搭建
    • steup下调用子组件方法
    • Vue3使用Typescript常见问题
      • 在 ts 中 axios 返回 not exist on type 'AxiosResponse'
      • 路由懒加载
      • 找不到模块“../views/HomeView.vue”或其相应的类型声明。
  • vue实现图片文件的显示和上传
  • composition-api
  • vue常用eslint配置模板
  • vue.config.js常用配置
  • vuepress-theme-vdoing本站使用主题
  • vue常见问题
  • 常用插件

  • 《Vuejs》
  • vue3
mrcdh
2022-01-25
目录

Vue3使用Typescript常见问题

# 在 ts 中 axios 返回 not exist on type 'AxiosResponse'

vue 的 axios 请求返回值调取时报下面这错误

Property 'content' does not exist on type 'AxiosResponse<any>'.Vetur(2339)
1

解决办法,修改 ts 声明文件.d.ts加入以下内容

declare module 'axios' {
  import * as axios from 'axios'
  interface AxiosInstance {
    (config: AxiosRequestConfig): Promise<any>
  }
}
1
2
3
4
5
6

# 路由懒加载

需要使用defineAsyncComponent来完成懒加载

import { defineAsyncComponent } from 'vue'
const _import = (path:string) => defineAsyncComponent(() => import(`/src/view/${path}.vue`));

const routes = [
    {
        path: '/',
        name: 'login',
        component: _import('account/login'),
        mate: {noAuth: true}
    }
]
1
2
3
4
5
6
7
8
9
10
11

# 找不到模块“../views/HomeView.vue”或其相应的类型声明。

//vite-env.d.ts
declare module "*.vue" {
  import { App, defineComponent } from "vue";
  const component: ReturnType<typeof defineComponent> & {
      install(app: App): void;
  };
  export default component;
}
1
2
3
4
5
6
7
8
#vue3#typescript
上次更新: 2023/09/22, 16:54:32
steup下调用子组件方法
vue实现图片文件的显示和上传

← steup下调用子组件方法 vue实现图片文件的显示和上传→

最近更新
01
uniapp常见问题
03-19
02
Vue3项目搭建
12-25
03
使用pnpm的monorepo组织项目
11-01
更多文章>
Theme by Vdoing | Copyright © 2020-2025 Mrcdh | 苏ICP备2020058908号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×