我试图弄清楚如何以一种可以在我的模板中显示它的方式访问我的登录用户电子邮件地址,但也可以在提交表单时在 axios 调用中访问它。我正在使用带有 laravel 5.8 的 vue 并尝试使用刀片和组件来做到这一点刀<test-component :email="{{ Auth::user()->email }}"></test-component>测试.vue<template><div> <div> Creator - <span> {{ email }} </span> </div></div></template>... props: [ email: '']如何正确存储电子邮件以在 axios 中显示和传递?
1 回答
MMMHUHU
TA贡献1834条经验 获得超8个赞
如果您正在Auth::user()->email通过道具,像这样:email="{{ Auth::user()->email }}"- 您可以this.email在您的vue组件中使用它来访问它,并通过axios简单的方式发送它:
axios.post('/user', {
email: this.email,
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
此外,如果您想让您的auth用户在您的组件中始终可用,您vue可以通过将其分配给window.user如下变量来实现:
<script> window.user = {{ Auth::user() }}</script>
然后在你的vue组件中你可以做这样的事情window.user.email。
另外,我鼓励你看看这篇文章——它会给你更多的例子。
希望这可以帮助。
添加回答
举报
0/150
提交
取消
