When I use axios I got this error:
[Vue warn]: Error in created hook: "TypeError: Cannot read property 'get' of undefined"
export default {
methods: {
loadUsers(){
axios.get("api/user").then(data => (this.users = data));
}
},
created() {
this.loadUsers();
}
}
Routes: api.php
Route::apiResources(['user' => 'API\UserController']);
Controller: API/UserController.php
public function index()
{
return User::latest()->paginate(5);
}
You need to import Axios first:
import axios from 'axios'
export default {
// ... axios.get will work now
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With