Reputation: 7885
I can't call function in the create hook. I always get the error 'loadEmployees is not defined'. Why is this not working?
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();
}
}
When I call the function on a button click and not in create
it works...
Im using Nuxt.js. Does this have to do with the error?
Upvotes: 0
Views: 151
Reputation: 138326
loadEmployees
should be called with this
:
this.loadEmployees()
new Vue({
created() {
this.loadEmployees();
},
methods: {
loadEmployees() {
console.log('loading employees...');
}
}
})
<script src="https://unpkg.com/[email protected]"></script>
Upvotes: 1