简体   繁体   English

Nuxt.js static 站点与使用 Vue.js 的动态单页应用程序?

[英]Nuxt.js static site with a dynamic single page application using Vue.js?

I am reading up on Static Site Generators for a client project and came across Vue.js and Nuxt.js which looks promising.我正在为一个客户项目阅读 Static Site Generators 并遇到 Vue.js 和 Nuxt.js 看起来很有希望。 As I have the choice between Vue.js and React, I would perfer Vue for now.因为我可以在 Vue.js 和 React 之间进行选择,所以我现在更喜欢 Vue。

The client's website is about 120 pages with predefined content that will not change often.客户的网站大约有 120 个页面,其中包含不会经常更改的预定义内容。 So it seems the perfect candidate for a static site - especially since his current WordPress site just got bashed by Google for abysmal page load times...因此,它似乎是 static 网站的完美候选人 - 特别是因为他当前的 WordPress 网站刚刚因为糟糕的页面加载时间而被谷歌抨击......

The "problem" or question is that beside these 120 pages there needs to be one page that is basically a single page application that dynamically fetches data from a backend through an API. “问题”或问题是,除了这 120 个页面之外,还需要一个页面基本上是一个单页面应用程序,它通过 API 从后端动态获取数据。 To code this dynamic page, it would be ideal if I could use Vue.js as well.要编码这个动态页面,如果我也可以使用 Vue.js 将是理想的。

I did find a lot of info about Nuxt.js with regards to static pages or server generated pages.我确实找到了很多关于 Nuxt.js 关于 static 页面或服务器生成页面的信息。 But my use case would be many static pages plus one static page that talks to an API and that static page should be made with Vue.js as well (while including the sitewide header, menu, footer, etc.) But my use case would be many static pages plus one static page that talks to an API and that static page should be made with Vue.js as well (while including the sitewide header, menu, footer, etc.)

Is that possible and has anybody done something similar?这可能吗?有人做过类似的事情吗? Thanks for every pointer!感谢每一个指针!

Yes, totally doable.是的,完全可行。 I recommend using something like strapi.io or contentful to create your pages with content per component.我建议使用类似 strapi.io 或 contentful 来创建包含每个组件内容的页面。

You would create each section of the site as a component under nuxtjs and the cms it self, see example below.您可以在 nuxtjs 和它自己的 cms 下将站点的每个部分创建为一个组件,请参见下面的示例。

https://strapi.io/blog/creating-strapi-dynamic-zone-in-nuxtjs-app https://strapi.io/blog/creating-strapi-dynamic-zone-in-nuxtjs-app

Under pages you create "_.vue" which will pick up any "slug" and that's how you get the content for your page, using the slug.在页面下,您创建“_.vue”,它将拾取任何“slug”,这就是您使用 slug 获取页面内容的方式。

Another example - https://raoulkramer.de/nuxt-js-static-page-generator-with-dynamic-pages/另一个例子 - https://raoulkramer.de/nuxt-js-static-page-generator-with-dynamic-pages/

Hope the above gives you a better idea.希望以上能给你一个更好的主意。

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

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