[英]Vue.js, How to send object in api link via axios?
所以我有GET|HEAD
api: api/users/{user}
,它調用函數App\\Http\\Controllers\\Api\\UserController@show
。 Laravel 中的這個函數是:
public function show($id){
return new UserShowResource(User::findOrFail($id));
}
如何將變量id
發送到我的函數。 我在某處找到了這個:
const helpVar = axios.get('/api/users/{this.$route.params.id}').then(response => {
this.users = response.data;
this.loading = false;
});
但它不起作用。 我試過axios.get('/api/users/1')
並且它返回給我id=1
用戶,所以問題出在 axios 中的這個鏈接上。
您的代碼不起作用,因為您使用了簡單的引號。 當您嘗試使用模板文字進行插值時,您必須將代碼更改為:
const helpVar = axios.get(`/api/users/{this.$route.params.id}`).then(response => {
this.users = response.data;
this.loading = false;
});
我認為你應該使用 ` 而不是 ' 這樣就可以通過 {this.$route.params.id} ;
const helpVar = axios.get(`/api/users/{this.$route.params.id}`).then(response => {
this.users = response.data;
this.loading = false;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.