【问题标题】:Uncaught (in promise) TypeError: Cannot read property 'data' of undefined未捕获(承诺中)类型错误:无法读取未定义的属性“数据”
【发布时间】:2018-08-26 12:46:46
【问题描述】:

我在使用 VueJS Laravel 时遇到了这个问题

这是我的 Home.vue

<template>
    <table>
        <tr v-for="models in model.data">
            {{models.nom}}
        </tr>
    </table>
</template>
<script>
import axios from 'axios'
export default{
    data() {
        return {
            model: {}
        }
    },
    created:function(){
        this.fetchDataResto()
    },
    methods: {
        fetchDataResto(){
            var vm = this
            axios.get('/test')
                .then(function response(){
                    Vue.set(vm.$data, 'model', response.model.data)
                })
        }
    }
}
</script>

这是我的 app.js

require("./bootstrap");
window.Vue = require("vue");
Vue.component('home', require('./components/Home.vue'));

var app = new Vue({
  el: "#app"
});

执行Uncaught (in promise) TypeError: Cannot read property 'data' of undefined at response (app.js:47293)后出现此消息错误

我不知道为什么数据未定义

谢谢

【问题讨论】:

    标签: vue.js vuejs2


    【解决方案1】:

    我解决了这个

    fetchDataResto(){
                    var vm = this
                    axios.get('/test')
                        .then(function (response){
                            Vue.set(vm.model, 'model', response.data)
                        })
                }
    

    【讨论】:

      【解决方案2】:
      fetchDataResto(){
                  var vm = this
                  axios.get('/test')
                      .then(function (response){
                          Vue.set(vm.$data, 'model', response.model.data)
                      })
              }
      

      您忘记设置response 变量。 ;)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-29
        • 2020-12-15
        • 2017-08-12
        • 1970-01-01
        • 2021-05-13
        • 1970-01-01
        • 2023-03-31
        • 1970-01-01
        相关资源
        最近更新 更多