vue + ts中的shims-vue.d.ts文件的作用,在ts中引入vue-echarts等vue文件 TypeScript 导入 JSON Module –resolveJsonModule(Shoes Vue in Vue + ts d. The function of TS file is to import Vue echarts and other Vue files in TS, typescript into JSON module — resolvejsonmodule)

shims-vue.d.ts是为了 typescript 做的适配定义文件,因为.vue 文件不是一个常规的文件类型,ts 是不能理解 vue 文件是干嘛的,加这一段是是告诉 ts,vue 文件是这种类型的。这一段删除,会发现 import 的所有 vue 类型的文件都会报错。

/** * shims-vue.d.ts的作用 * 为了 typescript 做的适配定义文件,因为.vue 文件不是一个常规的文件类型,ts 是不能理解 vue 文件是干嘛的, * 加这一段是是告诉 ts,vue 文件是这种类型的。 * 可以把这一段删除,会发现 import 的所有 vue 类型的文件都会报错。 */

declare module '*.vue' { //declare声明宣告, 声明一个ambient module(即:没有内部实现的 module声明)
import Vue from 'vue'
export default Vue
}
// typings.d.ts

declare module '*.json' {
    const value: any;
    export default value;
}



import json from 'src/assets/json/users.json'

declare module ‘vue-echarts’ // 引入vue-echarts<script lang=”ts”> /* eslint-disable @typescript-eslint/camelcase */ import { Vue, Component, Watch } from ‘vue-property-decorator’ import ECharts from ‘vue-echarts’ //报错,按上面的方法在shims-vue.d.ts文件中引入即可 import ‘echarts/lib/chart/line’ import ‘echarts/lib/chart/pie’ import ‘echarts/lib/component/tooltip'</script>————————————————版权声明:本文为CSDN博主「小小前端–可笑可笑」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。原文链接:https://blog.csdn.net/qq_41860203/article/details/110912759

————————

shims-vue. d. TS is an adaptation definition file for typescript because Vue file is not a regular file type. TS cannot understand what Vue file is. This paragraph is added to tell ts that Vue file is of this type. After deleting this paragraph, you will find that all Vue types of files imported will report errors.

/** * shims-vue. d. The role of TS * is to create an adaptation definition file for typescript because Vue file is not a regular file type. TS cannot understand what Vue file is for. * this paragraph is added to tell ts that Vue file is of this type* You can delete this paragraph, and you will find that all Vue types of files imported will report errors*/

declare module '*.vue' { //declare声明宣告, 声明一个ambient module(即:没有内部实现的 module声明)
import Vue from 'vue'
export default Vue
}
// typings.d.ts

declare module '*.json' {
    const value: any;
    export default value;
}



import json from 'src/assets/json/users.json'

Declare module ‘Vue echarts’ / / introduce Vue echarts & lt; script lang=”ts”> /* Eslint disable @ typescript eslint / camelCase * / import {Vue, component, watch} from ‘Vue property decorator’ import echarts from ‘Vue echarts’ / / an error is reported. Follow the above method in the ships Vue d. Import ‘charts / lib / chart / line’ import ‘charts / lib / chart / pie’ import ‘charts / lib / component / tooltip’ & lt/ script>———————————————— Copyright notice: This is the original article of CSDN blogger “little front end — ridiculous”. It follows CC 4.0 by-sa copyright agreement. Please attach the source link and this notice for reprint. Original link: https://blog.csdn.net/qq_41860203/article/details/110912759