1.在使用vue+typescript 構建項目的時候,使用變量動態獲取屬性值的時候,ts解析器會報一個錯誤。
**
var key = 'name';
this[key] = 123;
// 這裏會提示一個語法錯誤 **Element implicitly has an 'any' type because type 'About' has no index signature.**
console.log(this[key])
// 這裏會提示一個語法錯誤 **Element implicitly has an 'any' type because type 'About' has no index signature.**
2.解決辦法
在組件頂部聲明一個declare
declare module 'vue/types/vue' {
interface Vue {
[key: string]: any,
}
}