一、axios

  1. 引入 import axios from 'axios';
  2. 使用 created(){
  3. axios.get("http://124.70.134.133:7001/api/movie/top250").then((res) => {
  4. this.tops = res.data.res
  5. });
  6. },

二、taro.request

  1. 可以引用taro使用taro发送http请求,使用方法与wx.request一致
  2. 注意回调函数需要写成箭头函数去指向vc,否则thisundefined,因为是引用的taro
  1. Taro.request({
  2. url: 'http://139.9.127.189:7000/api/movies/top250',
  3. method: 'GET',
  4. success: res=>{
  5. console.log(this);
  6. this.top250 = res.data.res;
  7. },
  8. fail: function(err) {
  9. console.log(err);
  10. },
  11. })