美文网首页
webpack配置proxy跨域

webpack配置proxy跨域

作者: noyanse | 来源:发表于2019-01-05 19:32 被阅读0次

豆瓣接口地址
http://api.douban.com/v2/movie/top250
http://api.douban.com/v2/movie/top250?start=25&count=25 参数

webpackDevServer.config.js

proxy: {
// 当你请求是以/api开头的接口,则我帮你代理访问https://api.douban.com
        '/api': {
          target: 'http://api.douban.com',
          pathRewrite: {'^/api' : ''},
          changeOrigin: true,     // target是域名的话,需要这个参数,
          secure: false
        },
    },

获取

// http://localhost:3000 本地地址
        axios.get('http://localhost:3000/api/v2/movie/top250')
        .then(res => {
            const smallSrc = res.data.subjects[0].images.small
            // 根据路径拿到图片大小
            let img = new Image() 
            img.src = smallSrc
            img.onload = function() {
                console.log(img.width, img.height)
            }
        })

相关文章

网友评论

      本文标题:webpack配置proxy跨域

      本文链接:https://www.haomeiwen.com/subject/ytydrqtx.html