vue + ts遇到的问题总结

1 篇文章 0 订阅

问题1:Element implicitly has an ‘any’ type because type ‘TraceTool’ has no index signature.

问题1问题描述
解决方法:在组件头部加这段代码

declare module 'vue/types/vue' {
    interface Vue {
        [key: string]: any,
    }
}

问题1解决方法
参考链接:vuejs+typescrpt this[key] 使用变量获取this属性报错解决办法Elemen

问题2:for (… in …) statements must be filtered with an if statement

问题2问题描述
解决方法:

for (const key of Object.keys(obj)) {
	this[key] = obj[key]
}

解析:Object.keys()方法,返回的是对象本身的可枚举属性

参考链接:报错tslint/ codelyzer / ng lint error: “for (… in …) statements must be filtered with an if statement

问题3:Could not find a declaration file for module ‘vue-json-viewer’

问题3问题描述
试了很多方法,其中包括:在tslint.json添加下面这段代码,并没有起作用

"noImplicitAny":  false

解决方法:

// js
import JsonViewer from 'vue-json-viewer';
Vue.component('JsonViewer', JsonViewer);

// html
<json-viewer :expand-depth=2 copyable :value="this.currentSpan.outputValue || ''"></json-viewer>

参考链接:[1] Could not find a declaration file for module ‘vue-xxx’

问题4:Value of key ‘XX’ is not a string!

问题4描述
解决方法:在使用这个插件的地方,添加silentTranslationWarn: true 这段代码

const i18n = new VueI18n({
  locale: language,
  messages: {
    zh,
    en,
  },
  silentTranslationWarn: true // 重点
});
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值