【问题标题】:Using laravel session variable in vue component在 vue 组件中使用 laravel 会话变量
【发布时间】:2020-11-16 09:24:40
【问题描述】:

我是 vue Js 的新手,当我只使用刀片时,我曾经这样做过:

{{ Auth::user()->name }}

如何在刀片组件中做到这一点?

谢谢。

【问题讨论】:

  • 使用api获取auth用户
  • 之后我可以将响应存储在会话变量中吗?
  • 没有 vuex 存储或本地存储

标签: laravel vue.js


【解决方案1】:

使用 Vue 的 props 能够通过标记将属性传递给 Vue 的组件。

<auth-details :auth-name="{{ Auth::user()->name }}">
</auth-details>

在你的 vue 组件中,

Vue.component('auth-details', {
    props: ['authName'],
});

您可以使用this.authName 访问它。

注意:在HTML中你需要用kebab-case写属性名,而在Vue端你需要写成camelCase。

【讨论】:

  • 如果以上答案有帮助,您能否接受答案或编辑以上答案,以便我和其他人知道您所做的更改
  • 我还不能接受,因为我的声誉不够。
  • 我解决了将标题作为组件的问题: {{nome}} this.$axios.get(' auth/pegaUtilizador') .then(function (response) { if(response.status==200){ self.nome = response.data.name; }else{ alert("Error "); } }
猜你喜欢
  • 1970-01-01
  • 2020-07-26
  • 2015-04-09
  • 1970-01-01
  • 2021-09-30
  • 1970-01-01
  • 2021-03-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多