我试图从带有Vue3 & TypeScript中axios的Google电子表格中获取数据。
这是我第一次使用vue3而不是Vue2。
我有一个错误:属性'items‘在'BiblioAll'类型上不存在
这是我的密码
<template>
/// My template
</template>
<script lang="ts">
import { Vue } from "vue-class-component";
export default class BiblioAll extends Vue {
data () {
return{
items: {} as any
}
}
created(){
this.axios.get("https://spreadsheets.google.com/feeds/list/1ZTO87yKX4NkQ7I641eL01IcGzlnugdK_Nkou5cSy1kQ/1/public/values?alt=json")
.then(response => (this.items = response))
}
}
}
</script>
<style scoped>
/// Styles
</style>有人知道怎么解决吗?
谢谢
发布于 2021-06-28 10:46:00
Vue 3很好地支持类型记录,所以我建议不要使用vue类组件,只需使用defineComponent创建组件就可以得到类型推断,如下所示:
<template>
/// My template
</template>
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent( {
data () {
return{
items: {} as any
}
},
created(){
this.axios.get("https://spreadsheets.google.com/feeds/list/1ZTO87yKX4NkQ7I641eL01IcGzlnugdK_Nkou5cSy1kQ/1/public/values?alt=json")
.then(response => (this.items = response))
}
}
})
</script>
<style scoped>
/// Styles
</style>发布于 2021-06-28 10:45:31
在items类中定义BiblioAll
https://stackoverflow.com/questions/68161947
复制相似问题