[Vue 警告]:创建的钩子出错:“TypeError:无法设置未定义的属性”

Cod*_*rPJ 4 html javascript vue.js vue-component vuejs2

我正在创建一个 VueJS 应用程序。我有一个子组件 Child.vue,数据从父组件传递给它。

儿童.vue

export default{

    props:['info'],

    data: function(){
        return{
            timeValue:{
                minutes: '',
                hours: ''
            }
        }
    },
    created: function(){
        
        console.log("Printing inside created of Child ",this.info);
        this.convertMins(this.info[0][2]);
        
    },

    methods:{
        convertMins: (minutes) => {
            console.log("Printing inside convert mins", this);
            if(minutes===0){
                this.timeValue.minutes = 0;
                this.timeValue.hours = 0;
            }
            if(minutes===60){
                this.timeValue.hours = 1;
                this.timeValue.minutes = 0;
            }
            if(minutes>60){
                this.timeValue.hours = Math.floor(minutes/60);
                this.timeValue.minutes = minutes % 60;
            }
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

我的父组件看起来像这样,

父.vue

import Child from './Child.vue';

export default {
data(){
	return{
        info:[ ],

        errors: []
	}
},

created: function(){

  this.accessInformation();
},

methods: {
    
    accessInformation: function(){
    axios.get(localhost:3000/retrieveInfo)
    .then(response =>{
    console.log(response.data.rows[3]);
    this.info.push(response.data.rows[3]);
   })
   .catch(e => {
            this.errors.push(e);
   })
 }
},

components: {								
    'child': Child,
    
  }
}
Run Code Online (Sandbox Code Playgroud)
<template>
 <div>
   <child v-bind:info="info" v-if="info.length > 0"></child>
 </div>
</template>
Run Code Online (Sandbox Code Playgroud)

当我尝试运行应用程序时,出现这样的错误,

错误

在此处输入图片说明

为什么我收到这个错误?我是 VueJS 的新手。有人可以帮我吗?

Bot*_*tje 6

不要使用箭头函数来定义方法。请参阅https://vuejs.org/v2/guide/instance.html#Data-and-Methods 上的警告框