在TypeScript文件中导入Vue组件 [英] Importing Vue components in TypeScript file
本文介绍了在TypeScript文件中导入Vue组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试将Vue.js与TypeScript一起使用,并且遇到了
解决方案
声明模块"* .vue"{从"vue"导入Vue导出默认Vue}
然后写:
从"./App.vue"导入应用
代替
从"./App"导入应用
I have been trying to use Vue.js with TypeScript and I came across this repo.
I faced issues here that I am getting error while importing Vue Single Component File from TypeScript. I am using Visual Studio Code. Please see error below.
main.ts:
// The Vue build version to load with the 'import' command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import * as Vue from 'vue'
import App from './App'
/* eslint-disable no-new */
new Vue({
el: '#app',
template: '<App/>',
components: { App }
})
VS Code error:
1 ERROR • main.ts [ts] Cannot find module './App'. (4 17)
解决方案
From Alex Jover:
If your editor is yelling at the line import App from './App' in main.js file about not finding the App module, you can add a vue-shim.d.ts file to your project with the following content:
declare module "*.vue" {
import Vue from 'vue'
export default Vue
}
and write :
import App from './App.vue'
instead of
import App from './App'
这篇关于在TypeScript文件中导入Vue组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文