首页 > 代码库 > vue写请求接口--请求参数的变量要在return里面声明

vue写请求接口--请求参数的变量要在return里面声明

//谨记return里面是返回所有声明的变量的名字,数组以及对象等等
export default {
  data () {
    return {
//所有的变量都是写在data 的return里面的,主要错误点在于请求参数的变量要在这里声明;
      imgGroup: {
        user: require(‘../static/images/icon/user-ava.png‘),
        payment: require(‘../static/images/icon/wait-payment.png‘),
        delivery: require(‘../static/images/icon/wait-delivery.png‘),
        receive: require(‘../static/images/icon/wait-receive.png‘),
        completed: require(‘../static/images/icon/order-completed.png‘),
        detail: require(‘../static/images/icon/bonus-detail.png‘),
        card: require(‘../static/images/icon/bonus-card.png‘),
        manage: require(‘../static/images/icon/address-manage.png‘),
        maket: require(‘../static/images/icon/after-maket.png‘),
        jfs: require(‘../static/images/icon/about-jfs.png‘)
      },
      requestUrl: {
        scoreTotal: ‘/scoreTotal‘
      },
      requestParam: {
        scoreTotal: {//这里是要传递的参数
          userId: "2768",
          token: "b15dJIVKbfX1vfODv78erjDJwZre1QVhbzYzUYj2ep7uM07vFE9BCA==",
          ppInfo: "AxMDA3NDkw%Mjc2ODE4Mz",
          browser: "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4",
          clientType: 3,
          version: "1.0.0001.0613"
        }
      },
      credits: "",//当前积分,这里是页面所需要显示声明的变量
      deductCash: "",//可抵扣金额
    }
  },
  created () {
    var vm = this;
    vm.creditRequest();
  },
  methods: {
    //获取总积分
    creditRequest(){
      var vm = this;
      vm.$http.post(vm.requestUrl.scoreTotal, vm.requestParam.scoreTotal, {
        headers: {
          "X-Requested-With": "XMLHttpRequest"
        },
        timeout: 5000,
        emulateJSON: true
      }).then(function (res) {
        var data = http://www.mamicode.com/res.data;>

  

vue写请求接口--请求参数的变量要在return里面声明