vue2.0初学者使用axios发送请求,一般会自己建立一个请求文件方便自己做测试用,在传参的过程按F12可能会发现参数没有传过去.
如果是get请求,传参方式如下(此处以vue 中mothods方法里的函数为例):
methods: { loginFun(){ let _this = this; _this.$axios.get('../../../static/test.json',{ params:{ loginName:this.username, password:this.password } }) .then(function (response) { console.log(response); }).catch(function (error) { console.log(error) }) } }
如果是post:
methods: { loginFun(){ let _this = this; _this.$axios.get('/api/user',{ loginName:this.username, password:this.password }) .then(function (response) { console.log(response); }).catch(function (error) { console.log(error) }) } }
如果是自己练习,没有后台接口的话,建议用get请求,这样不会报错