TS2339: 属性 'posts' 类型不存在
TS2339: Property 'posts' does not exist on type
这是我的代码,我尝试在 ionic 5 中使用 Axios
调用 API
import axios from "axios";
import {
IonCard,
IonCardContent,
IonCardSubtitle,
IonCardTitle
} from "@ionic/vue";
export default {
name: "Tab1",
components: {
IonCard,
IonCardContent,
IonCardSubtitle,
IonCardTitle
},
data() {
return { posts: [] };
},
created() {
axios.get("http://gautammenaria.com/wp-json/wp/v2/posts").then(response => {
this.posts = response.data;
});
}
};
出现此错误(也按预期获取数据)
TS2339:属性 'posts' 在类型 '{ name: string; 上不存在;组件:{
不确定是什么
您应该使用 defineComponent
函数构建您的组件以获得类型推断:
import axios from "axios";
import {
IonCard,
IonCardContent,
IonCardSubtitle,
IonCardTitle
} from "@ionic/vue";
import {defineComponent} from 'vue'
export default defineComponent({
name: "Tab1",
components: {
IonCard,
IonCardContent,
IonCardSubtitle,
IonCardTitle
},
data() {
return { posts: [] };
},
created() {
axios.get("http://gautammenaria.com/wp-json/wp/v2/posts").then(response => {
this.posts = response.data;
});
}
});
这是我的代码,我尝试在 ionic 5 中使用 Axios
调用 APIimport axios from "axios";
import {
IonCard,
IonCardContent,
IonCardSubtitle,
IonCardTitle
} from "@ionic/vue";
export default {
name: "Tab1",
components: {
IonCard,
IonCardContent,
IonCardSubtitle,
IonCardTitle
},
data() {
return { posts: [] };
},
created() {
axios.get("http://gautammenaria.com/wp-json/wp/v2/posts").then(response => {
this.posts = response.data;
});
}
};
出现此错误(也按预期获取数据)
TS2339:属性 'posts' 在类型 '{ name: string; 上不存在;组件:{
不确定是什么
您应该使用 defineComponent
函数构建您的组件以获得类型推断:
import axios from "axios";
import {
IonCard,
IonCardContent,
IonCardSubtitle,
IonCardTitle
} from "@ionic/vue";
import {defineComponent} from 'vue'
export default defineComponent({
name: "Tab1",
components: {
IonCard,
IonCardContent,
IonCardSubtitle,
IonCardTitle
},
data() {
return { posts: [] };
},
created() {
axios.get("http://gautammenaria.com/wp-json/wp/v2/posts").then(response => {
this.posts = response.data;
});
}
});