0

我正在尝试在 vue js 组件中获取登录用户,但我无法正确使用它。我收到一个错误 Uncaught TypeError: Cannot read property 'getAttribute' of null

我在 app.blade 文件中添加了以下代码

   @if (Auth::check()) 
            <meta name="user_id" content="{{ Auth::user()->id }}" />
         @endif

在 app.js 我添加了

Vue.prototype.$userId = document.querySelector("meta[name='user_id']").getAttribute('content');

在我的组件中

            data() {
            return{ 
                user_id: this.$userId,
              }
            }
4

0 回答 0