//谨记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); } }) }, } }
时间: 2024-10-28 20:26:22