鍍金池/ 問(wèn)答/HTML/ 如何用vue的axios動(dòng)態(tài)請(qǐng)求豆瓣這條數(shù)據(jù)

如何用vue的axios動(dòng)態(tài)請(qǐng)求豆瓣這條數(shù)據(jù)

跨域請(qǐng)求豆瓣這條數(shù)據(jù)https://api.douban.com/v2/mov...

這里的1764796是動(dòng)態(tài)的,有辦法向下面一樣的寫法請(qǐng)求嗎

圖片描述

這是我參照網(wǎng)上一個(gè)大神的寫法,用node.js請(qǐng)求,這里的params中的參數(shù)是帶問(wèn)號(hào)的。

回答
編輯回答
祉小皓

如果是跨域問(wèn)題,即出現(xiàn)

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://api.douban.com' is therefore not allowed access.

那么有兩種方式可以試一下

  1. 由后端代理轉(zhuǎn)發(fā)請(qǐng)求

  2. 前端jsonp,可以使用這個(gè)庫(kù)https://github.com/axios/axio...

$ npm install jsonp --save
var jsonp = require('jsonp');
jsonp('http://www.example.com/foo', null, function (err, data) {
  if (err) {
    console.error(err.message);
  } else {
    console.log(data);
  }
});

如果不是跨域問(wèn)題,只是想發(fā)起get請(qǐng)求,看看官網(wǎng)……
https://github.com/axios/axios/

2017年9月27日 07:32
編輯回答
款爺
let id= '1764796'
url = 'https://api.douban.com/v2/movie/subject/' + id
axios.get(url).then(res=>{ ... })
2018年6月1日 18:19