简体   繁体   English

Laravel 8,带有 Inertiajs 的 Vue 3 在 ssr 设置时出错

[英]Laravel 8, Vue 3 with Inertiajs got error while ssr setup

I followed all the server-side rendering steps on inertia website docs, and installed all dependencies, but couldn't manage to set up this with Laravel 8 and Vue 3.我遵循了惯性网站文档上的所有服务器端渲染步骤,并安装了所有依赖项,但无法使用 Laravel 8 和 Vue 3 进行设置。

Got this kind of error:遇到这种错误:

[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)

Any ideas?有任何想法吗?

You're trying to access the document variable (which is only available in client side).您正在尝试访问document变量(仅在客户端可用)。

You can avoid this by check if you're running the code in the server or in the browser using something like您可以通过检查您是在服务器中运行代码还是在浏览器中使用类似的东西来避免这种情况

const isServer = typeof window === 'undefined'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM