豆瓣接口地址
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)
}
})