简体   繁体   English

Vue.js TypeError:消息无法读取未定义的属性“ singlePost”

[英]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.

相关问题 “类型错误:无法读取未定义的属性‘服务’”Vue.js + Vuefire - "TypeError: Cannot read property 'servicios' of undefined" Vue.js + Vuefire TypeError:无法读取未定义的属性“标题”。 Vue.js - TypeError: Cannot read property 'title' of undefined. Vue.js TypeError:无法读取未定义的Flatpickr&Vue.js属性“ add” - TypeError: Cannot read property 'add' of undefined" Flatpickr & Vue.js Vue.js - 类型错误:无法读取未定义的属性“标题” - Vue.js - TypeError: Cannot read property 'title' of undefined 无法读取vue.js中“未定义”的属性 - Cannot read property of 'Undefined' in vue.js Vue.js 计算属性:[Vue 警告]:渲染错误:“TypeError:无法读取未定义的属性‘userId’” - Vue.js computed property : [Vue warn]: Error in render: "TypeError: Cannot read property 'userId' of undefined" TypeError:无法读取未定义的“已创建”属性,未定义错误“Vue” Vue.js 3 - TypeError: Cannot read property 'created' of undefined, error 'Vue' is not defined Vue.js 3 vue.js:属性或方法“”未定义,渲染错误:“TypeError:无法读取未定义的属性” - vue.js : Property or method "" is not defined, Error in render: "TypeError: Cannot read property '' of undefined" data()中的错误:“ TypeError:无法读取未定义的属性'length'”(Vue.js) - Error in data(): “TypeError: Cannot read property 'length' of undefined” (Vue.js) vue.js push给出TypeError:无法读取未定义的属性“名称” - vue.js push gives TypeError: Cannot read property 'name' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM