没有从 api 控制器获取任何数据到 vue 组件中
我在 vue 3 中有一个名为 index 的组件,它获取用户表单数据并将其传递到 laravel 中的 api 控制器。
async submitForm() {
try {
await axios.post(
"/api/show",
{
firstname: this.form.firstname,
email: this.form.email,
},
);
} catch (error) {
console.error("error");
}
},
我试图通过以下方法将发送到控制器的数据获取到另一个名为 show 的组件上,我得到的只是空字符串,我不明白原因。任何指南将不胜感激。
loadProductDetails() {
axios.post("api/show")
.then(({data}) => (this.products = data));
},
I have a component in vue 3 named index which gets the user form data and passes it onto api controller in laravel.
async submitForm() {
try {
await axios.post(
"/api/show",
{
firstname: this.form.firstname,
email: this.form.email,
},
);
} catch (error) {
console.error("error");
}
},
and I'm trying to fetch the data sent into the controller via following method onto another component named show and all I'm getting is empty string and I don't understand the reason. Any guide would be really appreciated.
loadProductDetails() {
axios.post("api/show")
.then(({data}) => (this.products = data));
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了问题。这是因为我试图从两种不同的路线中获得响应,但是第一个路由已经在获取后响应数据,第二个路由是返回空字符串并替换我已经从响应中收到的数据。
只需将响应数据保存到本地存储中,然后从另一个组件中获取问题就可以解决问题。
Solved the issue. It was because I was trying to get response from two different routes but the first one was already fetching the post response data and second one was returning the empty string and replacing the data I already recieved from the response.
Simply saving the response data into local storage and getting it from another component solved the issue.