API 浏览器
Quasar CLI with Webpack - @quasar/app-webpack
SSR FAQ

为什么我遇到了 Hypination 错误?(Why am I getting hydration errors?)

¥Why am I getting hydration errors?

查看我们的 客户端水合 页面。当你遇到 hydration 错误时,这意味着服务器上渲染的 HTML 与客户端渲染的 HTML 不匹配。此错误仅在开发过程中出现(而不是在生产环境中),并且在你发布网站之前务必解决。是否有某些内容只能在客户端生成?然后使用 QNoSsr

¥Take a look at our Client Side Hydration page. When you get hydration errors, it means the HTML rendered on the server does not match the equivalent HTML rendered on client-side. This error will appear only when developing (and NOT on production) and it definitely needs to be addressed, before you release your website. Is there some content that you can only generate on client-side? Then use QNoSsr.

¥Why doesn’t importing Platform and Cookies work?

构建 SSR 应用时,请仅使用 $q.platform / $q.cookies 表单。或者,在服务器端时,这是另一个如何使用它的示例:

¥When building for SSR, use only the $q.platform / $q.cookies form. Alternatively, when on server-side, this is one more example of how you can use it:

// example with Platform; same thing for Cookies
import { Platform } from 'quasar'

// you need access to `ssrContext`
function (ssrContext) {
  const platform = process.env.SERVER
    ? Platform.parseSSR(ssrContext)
    : Platform // otherwise we're on client

  // platform is equivalent to the global import as in non-SSR builds
}

ssrContext 可在 启动文件预取功能 中使用,并以参数形式提供。

¥The ssrContext is available in the Boot Files or the PreFetch Feature, where it is supplied as a parameter.

这样做是有充分理由的。在纯客户端应用中,每个用户都会在其浏览器中使用该应用的全新实例。对于服务器端渲染,我们想要的是相同的。每个请求都应具有一个全新、独立的应用实例,以避免跨请求状态污染。因此 平台Cookies 需要单独绑定到每个请求。

¥There is a good reason for this. In a client-only app, every user will be using a fresh instance of the app in their browser. For server-side rendering we want the same thing. Each request should have a fresh, isolated app instance so that there is no cross-request state pollution. So Platform and Cookies need to be bound to each request separately.

阅读 编写通用代码 文档页面也是一个好主意。

¥Also a good idea is to read the Writing Universal Code documentation page.

为什么 LocalStorage 和 SessionStorage 无法正常工作?(Why isn’t LocalStorage and SessionStorage working?)

¥Why isn’t LocalStorage and SessionStorage working?

在服务器端运行代码时,存储功能无法使用。Web Storage 是一个仅适用于浏览器的 API。

¥When running the code on server-side, the storage facilities can’t work. Web Storage is a browser only API.