[英]Vuejs and Laravel: How to use http get to pass an array to Laravel controller
我需要使用 vue http get 传递数组。 但我不知道该怎么做。我知道我可以使用(我正在使用 spatie/laravel-query-builder)'/users?filter[name]=John' 为 get 方法传递参数。
我有一个类别数组 = [10, 20, 100]; 类别的包含是 id。 我需要将 id 传递给 Laravel 控制器。
vue.js 调用 get
axios.get(url).then((res) => {
console.log(res.data);
})
.catch((err) => console.error(err));
您需要JSON.stringify
传递的数据并将此字符串分配给 get 参数(在本例中为: myArray
)。
const data = [{ id: 1 }, { id: 2 }]
const url = 'https://myendpoint.com'
axios.get(url, {
params: {
myArray: JSON.stringify(data)
}
}).then(res => console.log(res))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.