英文:
SSR pages also possible with dynamic elements?
问题
我们希望在我们的网站上使用SSR(预渲染页面)。在SSR页面上,我们也有像价格计算、带有数据的日历等动态元素。
在SSR中是否可能实现这个?
最好的问候,
Remco
英文:
We want to use SSR (pre-rendered pages) on our site. On the SSR pages we have also dynamic elements like price calculation, calendar with data ect.
Is this possible with SSR ?
best remco
答案1
得分: 1
如果你指的是动态路由,你可以使用generate.routes
或nitro.prerender.routes
来生成它们。详细信息请参考https://nuxt.com/docs/api/configuration/nuxt-config#routes。
例如,你可以拥有类似http://localhost:3000/calendar/01-01-2023
、http://localhost:3000/calendar/02-01-2023
等带有日期作为动态参数的URL。每个页面都具有不同的内容,路由和内容可以来自数据库、API、静态的.json
文件或@nuxt/content
。
如果你指的是页面上的数据会随着用户的互动而改变,例如,在特定路由上,用户添加产品到购物车时价格会发生变化,比如http://localhost:3000/cart
,那么这与预渲染无关,因为初始渲染将是一个空的购物车,价格计算为0,它会在后来动态变化。
购物车的示例可能不太完美,因为该页面通常位于受保护的路由后面,因此无法生成它,但你可以将相同的逻辑应用于公共页面。
英文:
If you mean dynamic routes, you can generate them using generate.routes
or nitro.prerender.routes
https://nuxt.com/docs/api/configuration/nuxt-config#routes.
For instance, you may have http://localhost:3000/calendar/01-01-2023
, http://localhost:3000/calendar/02-01-2023
etc with the date being a dynamic param in the url. With different content for each page, with routes and content coming from a database, an API, a static .json
file or @nuxt/content
.
If you mean that the data in the pages change with user interaction, for instance, the price changes when the user adds a product to the shopping chart on a specific route such as http://localhost:3000/cart
, that is not relevant for pre-render, since the initial render will be with an empty chart with price calculation equal to 0, and it will change dynamically later on.
The example of the cart, may be not perfect, since that page is usually behind a protected route, so you can't generate it, but you may apply the same logic to a public page.
答案2
得分: 0
参考Nuxt数据收集:https://nuxt.com/docs/getting-started/data-fetching
英文:
Sure, SSR can realize data dynamics, but it depends on the framework you use to decide how to do it!
Refer to Nuxt data collection:https://nuxt.com/docs/getting-started/data-fetching
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论