首页 > 移动平台 > 详细

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

时间:2018-11-14 18:01:00      阅读:878      评论:0      收藏:0      [点我收藏+]

最初我以为在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)
        })
    },

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

技术分享图片

 

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

原文:https://www.cnblogs.com/ldlx-mars/p/9959226.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!