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 = 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里面声明的更多相关文章
- formData请求接口传递参数格式
element ui组件方法的传递 //引入 组件. <el-upload class="avatar-uploader" :action="action" ...
- 动态生成简约MVC请求接口|抛弃一切注解减少重复劳动吧
背景 目前创建一个后端请求接口给别人提供服务,无论是使用SpringMVC方式注解,还是使用SpringCloud的Feign注解,都是需要填写好@RequestMap.@Controller.@Pa ...
- 【性能测试】:LR中解决接口请求中包含中文字符,服务器不识别的问题
在LR中,直接写的接口请求,如果请求字段包含中文字段,服务器会不识别,这个时候就要用到lr_convert_string_encoding这个函数: 具体用法: lr_convert_string_e ...
- LR中解决接口请求中包含中文字符,服务器不识别的问题
在LR中,直接写的接口请求,如果请求字段包含中文字段,服务器会不识别,这个时候就要用到lr_convert_string_encoding这个函数: 具体用法: lr_convert_string_e ...
- Postman系列四:Postman接口请求设置环境变量和全局变量、测试沙箱和测试断言、测试集运行与导入数据文件
一:Postman中接口请求设置环境变量和全局变量 全局变量和环境变量可以通过Pre-request Script和Tests设置,会在下面测试沙箱和测试断言中讲到. 全局变量的设置:官网参考http ...
- Vue + webpack 项目配置化、接口请求统一管理
准备工作 需求由来: 当项目越来越大的时候提高项目运行编译速度.压缩代码体积.项目维护.bug修复......等等成为不得不考虑而且不得不做的问题. 又或者后面其他同事接手你的模块,或者改你的bug ...
- vue打包后,接口请求404的完美解决方案
在开发环境中,和后台对接为了解决跨域问题,使用了代理,也就是vue的proxyTable,但是打包放到生产环境中去时,接口请求不到,404,原因是开发环境的代理并不能用到生产环境,但是直接在请求接口是 ...
- Java 请求webServce接口 带参数
public String getWebServiceByParams(String param){ //获取基金缴付记录 // Post请求的url,与get不同的是不需要带参数 URL postU ...
- httprunner学习3-extract提取token值参数关联(上个接口返回的token,传给下个接口请求参数)
前言 如何将上个接口的返回token,传给下个接口当做请求参数?这是最常见的一个问题了. 解决这个问题其实很简单,我们只需取出token值,设置为一个中间变量a,下个接口传这个变量a就可以了.那么接下 ...
随机推荐
- Light OJ 1060 - nth Permutation(组合数)
题目大意: 给你一个字符串,问这个字符串按照特定顺序排列之后,第n个字符串是哪个? 题目分析: 首先我们要会求解总个数.也就是共有len个字符,每个字符有ki个,那么总组合方式是多少种? 总组合方式就 ...
- [转]web调试工具总结(firebug/fidder/httpwatch/wireshark)
ONE:Firebug: Firebug是网页浏览器 Mozilla Firefox下的一款开发类插件, 现属于Firefox的五星级强力推荐插件之一.它集HTML查看和编辑.Javascript控制 ...
- EXP-00056: ORACLE error 6550 encountered报错;
SQL> exp sys/sys file=/home/oracle/sys.dmp full=y Export: Release 11.2.0.3.0 - Production on Wed ...
- python yeild使用
闲的蛋疼又想起之前看到的文章,想想还是拿来复习一遍写进博客里. 原文链接:https://www.ibm.com/developerworks/cn/opensource/os-cn-python-y ...
- HDOJ/HDU 2564 词组缩写(单词缩写)
Problem Description 定义:一个词组中每个单词的首字母的大写组合称为该词组的缩写. 比如,C语言里常用的EOF就是end of file的缩写. Input 输入的第一行是一个整数T ...
- 1629 B君的圆锥
#include <iostream> #include <queue> #include <stack> #include <cstdio> #inc ...
- OGG问题 ORA-01403的处理办法
认识logdump分析工具及常用命令:http://book.51cto.com/art/201202/319253.htm http://www.killdb.com/2012/09/01/gold ...
- php开发中的页面跳转方法总结
PHP页面跳转实现的功能就是将网站中一个网页跳转到另一个网页中.对于刚刚学习PHP语言的朋友来说,是必须要掌握的基础方法. 页面跳转可能是由于用户单击链接.按钮等触发的,也可能是系统自动产生的.页面自 ...
- Android NDK 【错误】The method loadLibrary(String) is undefined for the type Settings.Syste
[错误]The method loadLibrary(String) is undefined for the type Settings.System [解决方法] 不要加入包import andr ...
- [Angular 2] DI in Angular 2 - 1
Orgial aritial --> Link The problem with Angular 1 DI: Angular 2 DI: Solve the singletons problem ...