如何使“nuxtgenerate”生成的html完全静态?

hgl*_*hgl 3 javascript vue.js nuxt.js

我有一个非常简单的 vue 页面,位于pageas/index.vue

<template>
  <div>hello world</div>
</template>
Run Code Online (Sandbox Code Playgroud)

运行后nuxt generate,生成的html文件dist/index.html中没有任何“hello world”。

这意味着生成站点不是完全静态的。它仍然需要浏览器运行js来渲染最终的html,并且搜索引擎可能看不到vue页面中的html。

我想知道至少当 vue 页面是静态的(例如,没有asyncData或没有fetch指定)时,是否有办法让 nuxt 完全生成 html 文件?

Ahm*_*aki 6

在运行生成命令之前,首先将应用程序配置设置为universal(SSR) 模式。

在 nuxt.config.js 中:

export default {
  mode: 'universal'
}
Run Code Online (Sandbox Code Playgroud)

然后运行: npm run generate