开始开发

编辑页面

对 Expo 项目进行第一次修改,并在你的设备上实时查看效果。


For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.

1

启动开发服务器

要启动开发服务器,请运行以下命令:

Terminal
npx expo start

2

在你的设备上打开应用

运行上述命令后,你会在终端中看到一个二维码。扫描此二维码即可在你的设备上打开应用。

如果你使用的是 Android 模拟器或 iOS 模拟器,你可以分别按 ai 来打开应用。

遇到问题?

请确保你的电脑和设备连接到同一个 Wi-Fi 网络。

如果仍然不起作用,可能是路由器配置所致 — 这在公共网络中很常见。你可以在启动开发服务器时选择 Tunnel 连接类型,然后再次扫描二维码来解决这个问题。

Terminal
npx expo start --tunnel

使用 Tunnel 连接类型会使应用重新加载的速度明显慢于 LANLocal,因此在可能的情况下最好避免使用 tunnel。如果需要通过网络中的另一台设备访问你的机器,你可能需要安装并使用模拟器或仿真器来加快开发速度。

3

进行你的第一次修改

在代码编辑器中打开 src/app/index.tsx 文件并进行一次修改。

src/app/index.tsx
1717 <ThemedView style={styles.heroSection}>
1818 <AnimatedIcon />
1919 <ThemedText type="title" style={styles.title}>
20 欢迎使用&nbsp;Expo
20 你好,世界!
2121 </ThemedText>
2222 </ThemedView>
2323
设备上没有显示更改?

Expo Go 默认配置为在文件发生更改时自动重新加载应用,但我们还是来确认一下启用它的步骤,以防万一某些地方没有正常工作。

  • 确保你已在 Expo CLI 中启用开发模式

  • 关闭 Expo 应用并重新打开它。

  • 应用再次打开后,摇晃你的设备以显示开发者菜单。按 Cmd ⌘ + D

  • 如果你看到已启用 Fast Refresh,请将其切换。如果你看到 Disable Fast Refresh,请关闭开发者菜单。现在再试着做一次更改。


文件结构

下面,你可以熟悉默认项目的文件结构:

Files

app

Contains the app's navigation, which is file-based. The file structure of the src/app directory determines the app's navigation.

The app has two routes defined by two files: src/app/index.tsx and src/app/explore.tsx. The layout file in src/app/_layout.tsx sets up the tab navigator using the platform-specific AppTabs component.

功能

默认项目模板具有以下功能:

Default project

Two tabs in an Expo app

File-based routing

The app has two screens: src/app/index.tsx and src/app/explore.tsx. The layout file in src/app/_layout.tsx sets up navigation using a platform-specific AppTabs component that uses native tabs on Android and iOS, and Expo Router UI tabs on web.

Learn More