使用Vue实现调用接口加载页面初始数据

闲着没事写了一个电影推荐的网页,很简单,使用的是Vue的实现.

创新互联专注于企业营销型网站、网站重做改版、龙凤网站定制设计、自适应品牌网站建设、H5响应式网站商城网站开发、集团公司官网建设、成都外贸网站建设公司、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为龙凤等各大城市提供网站开发制作服务。

 let vm = new Vue({
  el:'#content',
  data:{
   name:'',
   pic:'',
   actor:'',
   detail:'',
   link:''
  },
  mounted:function () {
   this.getMovie();
  },
  methods:{
   getMovie:function () {
    var _this = this;
    let url = '/niuren/getRecommendFilm';
    axios.get(url).then(function (res) {
     _this.name = res.data.data.name;
     _this.pic = res.data.data.pic;
     _this.actor = res.data.data.actor;
     _this.detail = res.data.data.detail;
     _this.link =res.data.data.link;
    })
   },
   goLink:function () {
    var _this = this;
    window.location.href = _this.link;
   }
  },
 })

因为我使用的是axios, 在get方法中的this指向的这个函数,所以要在调用之前声明this的指向为Vue实例的this,

要不然就是赋值不成功,导致无法渲染(弄了半天)

以上这篇使用Vue实现调用接口加载页面初始数据就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持创新互联。


网页题目:使用Vue实现调用接口加载页面初始数据
当前地址:http://pwwzsj.com/article/pohoee.html