可以使用vue组件vue-jsonp github地址https://github.com/LancerComet/vue-jsonp
使用前需先安装vue-jsonp
npm install --save vue-jsonp
然后在使用的页面引用
import Vue from 'vue'
import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp)
如果是在vue commponent中使用,使用方法如下,this.$jsonp()
![](https://img.haomeiwen.com/i9020624/9ba827c8f369cfc5.png)
如果是在方法中使用,使用方法如下
![](https://img.haomeiwen.com/i9020624/7daaddaa815ed57b.png)
在项目中可以找一个getData.js专门放置接口请求,内容如下
![](https://img.haomeiwen.com/i9020624/431ecd626972a994.png)
在需要使用的地方调用时
getAuthor()
.then(json=>{
this.authorList=json.date;
})
.catch(err=>{
console.log(err);
});
网友评论