[英]Vue.js TypeError: Message Cannot read property 'singlePost' of undefined
I have blog in vue.js I want to preview each post separately. 我在vue.js中有一个博客,我想分别预览每个帖子。 I do this>
我这样做>
export default{
name: 'post',
props:['id'],
data(){
return {
singlePost: { }
}
},
created() {
BlogPostsApi.getPost(this.id)
.then(response => {
console.log(response)
this.singlePost = response.data
})
}
in blogPosts.js i have this code> 在blogPosts.js中,我有此代码>
import axios from'axios';
export default{
getPost (id) {
return axios.get('http://localhost:8000/api/posts/ddc/' + id)
.then(response => {
debugger
return response.data
})
}
}
When i'm debugging i get this error Message Cannot read property 'singlePost' of undefined 调试时出现此错误消息无法读取未定义的属性“ singlePost”
created() {
var self = this
BlogPostsApi.getPost(this.id)
.then(response => {
console.log(response)
self.singlePost = response.data
})
}
The problem is solved 问题已经解决了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.