【发布时间】:2020-11-16 09:24:40
【问题描述】:
我是 vue Js 的新手,当我只使用刀片时,我曾经这样做过:
{{ Auth::user()->name }}
如何在刀片组件中做到这一点?
谢谢。
【问题讨论】:
-
使用api获取auth用户
-
之后我可以将响应存储在会话变量中吗?
-
没有 vuex 存储或本地存储
我是 vue Js 的新手,当我只使用刀片时,我曾经这样做过:
{{ Auth::user()->name }}
如何在刀片组件中做到这一点?
谢谢。
【问题讨论】:
使用 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。
【讨论】: