Skip to content

项目安装

环境检查

nuxt3 需要 node.js 版本需要大于 20.x。可以使用 node -v 指令进行查看。

shell
$ node -v
v22.12.0

如果没有安装的,请访问 https://nodejs.org/zh-cn/ ,选择适合自己操作系统的最新 LTS 版本下载和安装;如果已经安装请用下面命令查看版本, 必须在 V20.0.0 及以上。

创建项目

nuxt 官方文档:

https://nuxt.com/docs/getting-started/introduction

1、新建项目

https://nuxt.com/docs/getting-started/installation

shell
npx nuxi init nuxt_0102

2、进入到项目根目录

shell
cd nuxt_0102

3、安装依赖

shell
pnpm install

pnpm 是 Node.js 的替代包管理器。它是 npm 的直接替代品,但速度更快、效率更高。

因为 pnpm 和 npm 不是同一个东西,需要另外安装。如果你没有,可以建议安装使用。直接使用 npx 或 npm 安装 pnpm。

4、运行项目

shell
pnpm nuxt dev

启动之后访问给出的地址,就可以看到默认的页面。

默认页面为 app.vue , 内部的代码为

vue

<template>
  <div>
    <NuxtRouteAnnouncer />
    <NuxtWelcome />
  </div>
</template>

其中 NuxtWelcome 是 nuxt4 的默认欢迎组件,后面需要进行替换。