您正在浏览 Nuxt 2 文档。前往 Nuxt 3 文档, 或了解更多关于 Nuxt 2 长期支持

Axios 使用方法

第一个示例展示如何使用 nuxt.config.js 文件的 env 属性添加 API URL,并在页面中轻松调用 API 而无需使用 URL


本示例中:

nuxt.config.js 包含:

  • publicRuntimeConfig 属性中添加 API URL。
  • 使用 modules 属性注册 @nuxtjs/axios 模块。

pages/index.vue - 使用 $axios 获取数据,使用 $config 获取 API URL。

Loading Sandbox...
Edit this page on GitHub Updated at Tue, Apr 14, 2026