typescript - 使用 TypeScript 的 Vue JS 材料设计
问题描述
我正在尝试将 Vue JS 材料设计与 TypeScript 一起使用,但不支持开箱即用。在此GitHub 问题之后,我一直在尝试添加声明自定义模块,但没有成功。我的应用程序是使用vue create my-app
命令创建的
我在 src: 中创建了一个新文件types/vue-material/index.d.ts
:
declare module 'vue-material' {
import _Vue from "vue";
export function MdButton(Vue: typeof _Vue, options?: any): void
export function MdContent(Vue: typeof _Vue, options?: any): void
export function MdTabs(Vue: typeof _Vue, options?: any): void
}
我添加了类型根并从以下位置排除了文件夹tsconfig
:
{
"compilerOptions": {
// ...
"typeRoots": [
"src/types",
"node_modules/@types"
]
},
// ...
"exclude": [
"node_modules",
"src/types"
]
}
但是尝试导入时仍然出现错误VueMaterial
:
import { MdButton } from 'vue-material';
Could not find a declaration file for module 'vue-material'. 'C:/.../my-app/node_modules/vue-material/dist/vue-material.js' implicitly has an 'any' type.
Try `npm install @types/vue-material` if it exists or add a new declaration (.d.ts) file containing `declare module 'vue-material';`
我做错了什么?
解决方案
推荐阅读
- c++ - 我的小项目有问题
- swift - 提取未填充字符串的范围
- python - 使用 Python Marshmallow 进行数据类型转换
- android - 在 android studio 中使用生物特征或锁屏凭据进行生物特征认证
- vb6 - OCX 错误“组件未正确注册”
- python - Google Cloud PubSub - 如何向 Cloud Function 发送多个参数
- android - 在android中使用ViewModel将数据从带有recyclerview的片段传递到另一个片段
- python - 在使用 glob 加载多个 CSV 时用 NaN 值填充缺失的列
- html - 如何制作包含背景图像的 CSS 类
- ios - iOS:当应用程序被 didEnterRegion 唤醒时如何启动更新位置?