【问题标题】:Laravel 8, Vue 3 with Inertiajs got error while ssr setupLaravel 8,带有 Inertiajs 的 Vue 3 在 ssr 设置时出错
【发布时间】:2022-07-04 21:08:37
【问题描述】:

我遵循了惯性网站文档上的所有服务器端渲染步骤,并安装了所有依赖项,但无法使用 Laravel 8 和 Vue 3 进行设置。

遇到这种错误:

[Vue warn]: Unhandled error during execution of created hook 
  at <App errors= {} key=null >
ReferenceError: document is not defined
    at Proxy.created (C:\Users\Name\desktop\php\laravel\infoajara-new\public\js\ssr.js:702:5)
    at callWithErrorHandling (C:\Users\Name\desktop\php\laravel\infoajara-new\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:157:36)
    at callWithAsyncErrorHandling (C:\Users\Name\desktop\php\laravel\infoajara-new\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:166:21)
    at callWithAsyncErrorHandling (C:\Users\Name\desktop\php\laravel\infoajara-new\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:176:21)
    at callHook (C:\Users\Name\desktop\php\laravel\infoajara-new\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:2951:5)    
    at applyOptions (C:\Users\Name\desktop\php\laravel\infoajara-new\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:2853:9)
    at finishComponentSetup (C:\Users\Name\desktop\php\laravel\infoajara-new\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:7091:9)
    at setupStatefulComponent (C:\Users\Name\desktop\php\laravel\infoajara-new\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:7003:9)
    at setupComponent (C:\Users\Name\desktop\php\laravel\infoajara-new\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:6933:11)
    at renderComponentVNode (C:\Users\Name\desktop\php\laravel\infoajara-new\node_modules\@vue\server-renderer\dist\server-renderer.cjs.js:198:17)

有什么想法吗?

【问题讨论】:

    标签: laravel vue.js server-side-rendering inertiajs


    【解决方案1】:

    您正在尝试访问 document 变量(仅在客户端可用)。

    你可以通过检查你是在服务器中运行代码还是在浏览器中使用类似的东西来避免这种情况

    const isServer = typeof window === 'undefined'
    

    【讨论】:

      猜你喜欢
      • 2021-06-05
      • 2021-04-13
      • 2021-04-09
      • 2021-11-01
      • 2023-01-05
      • 2022-01-04
      • 2021-01-07
      • 2022-10-30
      • 2021-09-09
      相关资源
      最近更新 更多