Nuxt 的一个强体验点是自动导入。
在 app/components/ 下的组件,通常不需要你手写 import:
<!-- app/components/AppAlert.vue -->
<template>
<div class="alert">
<slot />
</div>
</template>然后在页面里直接用:
<!-- app/pages/index.vue -->
<template>
<div>
<h1>今晚新闻</h1>
<AppAlert>这是一条头条提醒</AppAlert>
</div>
</template>这件事表面上只是少写几行 import,本质上是:
Nuxt 在帮你统一节目资源调度也就是:
- 组件按约定放位
- 编译器自动识别
- 类型系统自动补齐
- 构建系统自动切分
所以 Nuxt 给你的不是“偷懒”,而是工程组织的默认秩序。