//謹記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); } }) }, } }