• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
LDLX@Y火星
博客园    首页    新随笔    联系   管理    订阅  订阅

nuxtJs中直接使用自带的@nuxtjs/axios

最初我以为在nuxtjs中是需要重新npm install axios,但是其实nuxtjs自己集成了这个数据渲染方法

你只需在nuxt.config.js中配置一下就可以了

modules: [
    // Doc: https://github.com/nuxt-community/axios-module#usage
    '@nuxtjs/axios'
  ],
  /*
  ** Axios module configuration
  */
  axios: {
    proxy: true,
    prefix: '/api/',
    credentials: true
    // See https://github.com/nuxt-community/axios-module#options
  },

  proxy: {
    '/api/': { 
      target: 'https://h5api.zhefengle.cn',//这个网站是开源的可以请求到数据的
      pathRewrite: {
         '^/api/': '/',
         changeOrigin: true
      }    
    }
  },

然后在你的页面可以直接请求数据了

mounted() {
        this.$axios.get("/index.html").then(res=>{
            console.log(res)
        })
    },

最后进入这个页面,在控制台看到打印即表示请求成功了

 

posted @ 2018-11-14 17:38  火星黑洞  阅读(16762)  评论(7)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3