我无法在create挂钩中调用函数。我总是收到错误“未定义loadEmployees”。为什么这不起作用?
export default {
components: {
AppointmentSlot
},
data: function() {
return {
employees: [],
appointmentData : {
date: Number,
employee: String,
slotSize: Number
}
}
},
methods: {
onRequestSlots() {
console.log(this.appointmentData.date);
},
loadEmployees: function() {
console.log('loading...')
}
},
created() {
console.log('asd');
loadEmployees();
}
}
当我在按钮上单击而不是在create
中调用该函数时,它将起作用...
我正在使用Nuxt.js。这与错误有关吗?
答案 0 :(得分:1)
loadEmployees
应该用this
来调用:
this.loadEmployees()
new Vue({
created() {
this.loadEmployees();
},
methods: {
loadEmployees() {
console.log('loading employees...');
}
}
})
<script src="https://unpkg.com/vue@2.5.17"></script>