【问题标题】:Vue js in laravel [closed]laravel中的Vue js [关闭]
【发布时间】:2021-11-24 07:28:30
【问题描述】:

我将发布代码,我无法将数据存储在 tweets 数组中,我错在哪里?我正在使用 vue 和 laravel

<script>
    export default {
        mounted() {
         this.recupera_post()
        },
   
    data(){ 
        return{
             tweets:[]
        }
       
    },
    methods:{
        async recupera_post(){
            await axios.get('api/schedulepost')
            .then(function(response){
                console.log(response.data)
                app.tweets=response.data
                })
            }
        }
    }
    
</script>

【问题讨论】:

  • 错误是什么?更具体
  • 没有错误,只是不填充数组

标签: laravel vue.js


【解决方案1】:

你只需要写this.tweets你还需要将你的回调函数更改为箭头函数,以便你可以像这样访问你的状态

 async recupera_post(){
     await axios.get('api/schedulepost')
     .then((response) => {
       console.log(response.data)
       this.tweets = response.data
     })
  }
}

【讨论】:

  • TypeError: 无法设置未定义的属性(设置“推文”)
  • 将回调函数改为箭头函数
  • @carulom 检查我更新的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-07
  • 2019-12-14
  • 2020-06-23
  • 2019-10-03
  • 2020-02-19
相关资源
最近更新 更多