vue3 中使用 element-ui 时出现的 Property ‘$notify‘ does not exist on type ‘App‘.
欢迎使用Markdown编辑器上手研究了下 vue + typescript 开发 发现使用 element-ui之后 element库里的一些对vue的扩展方法无法使用比如调用 this.$notify 方法显示通知会报以下错误百度找了半天 找到几种方案强转 any(<any>this).$notifyas(this as any).$notify在类中增加声明private $no
·
vue3 中使用 element-ui 时出现的 Property ‘$notify‘ does not exist on type ‘App‘.
上手研究了下 vue + typescript 开发 发现使用 element-ui之后 element库里的一些对vue的扩展方法无法使用
比如调用 this.$notify
方法显示通知会报以下错误
百度找了半天 找到几种方案
- 强转 any
(<any>this).$notify
- as
(this as any).$notify
- 在类中增加声明
private $notify: any;
这几种办法异曲同工,但是我用的是typescript,遇到麻烦就转any 还用ts干嘛,仔细想了下这种问题出现的原因是typescript没有找到方法的声明,虽然vscode识别出来了但是ts编译器并不知道方法的存在。
解决办法
找到 tsconfig.json
在 types 节点下 加入 element-ui
来告诉编译器 我们用到了这个库,然后重启编译器 npm run serve
更多推荐
已为社区贡献1条内容
所有评论(0)