vue request data using jsonp
Vue when the requested data, cross-domain problems encountered, the server in order to guarantee the security of information on cross-domain requests to intercept, therefore, in order to solve cross-domain requests vue problem, use jsonp.
Installation jsonp
npm install --save vue-jsonp
Introduced
After installation jsonp incorporated in the main.js
import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp)
use
After introduction jsonp, jsonp cross-domain can be used to request data.
Note: Not all sites can use jsonp request background data, we need to back-office support jsonp.
var param = {
header: {
"content-type": "application/xml" // 豆瓣一定不能是json
}
};
this.$jsonp('https://douban.uieee.com/v2/movie/in_theaters',param).then(
(json) => {
console.log(json)
}).catvh(err => {
console.log(err)
})