Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue warn: Error in created hook: "TypeError: Cannot read property 'get' of undefined"

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);
    }
like image 628
Md. Nayem Avatar asked Sep 14 '25 17:09

Md. Nayem


1 Answers

You need to import Axios first:

import axios from 'axios'
export default { 
    // ... axios.get will work now
}
like image 94
Mike Harrison Avatar answered Sep 16 '25 06:09

Mike Harrison