码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-11-25 12:32:12      阅读:751      评论:0      收藏:0      [点我收藏+]

标签:iphone   images   变量   type   default   function   mac   parse   code   

//谨记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 = res.data;
        console.log(data);
        if (data.code == 200) {
          vm.credits = data.amount;//当前积分,这里是页面所需要显示的变量的请求返回的数据
          vm.deductCash = parseFloat(data.amount / 100).toFixed(2);//可抵扣金额
          console.log(vm.credits, vm.deductCash);
        } else if (data.code == 501) {
          alert(data.desc);
        } else {
          alert(data.desc);
        }
      })

    },
  }
}

  

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

标签:iphone   images   变量   type   default   function   mac   parse   code   

原文地址:http://www.cnblogs.com/kpengfang/p/6100874.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!