gpt4 book ai didi

javascript - Vue 警告 : Error in created hook: "TypeError: Cannot read property ' get' of undefined"

转载 作者:行者123 更新时间:2023-12-05 00:38:41 27 4
gpt4 key购买 nike

当我使用 axios 时,出现此错误:

[Vue 警告]:创建钩子(Hook)时出错:“TypeError:无法读取未定义的属性 'get'”

export default {
methods: {
loadUsers(){
axios.get("api/user").then(data => (this.users = data));
}
},
created() {
this.loadUsers();
}
}

路线:
api.php
Route::apiResources(['user' => 'API\UserController']);

Controller :
API/用户 Controller .php
public function index()
{
return User::latest()->paginate(5);
}

最佳答案

你需要先导入axios:

import axios from 'axios'
export default {
// ... axios.get will work now
}

关于javascript - Vue 警告 : Error in created hook: "TypeError: Cannot read property ' get' of undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54117868/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com