1 跳转页面传值方法1:

this.$router.push({path:‘这个里面写的就是要跳转到的路由地址,记住前面加上斜杠,代表绝对路径’,query:{key:value}})

跳转到的页面获取传过来的数据的方法:this.$route.query.key

这种方法会导致参数拼接到地址栏上

2 跳转页面传值方法2:

edit(row){

this.$router.push({name:‘路由的name’,params:{key:row.id}})

}

跳转页面如何获取传过来的数据的方法:this.$route.params.key

这种方法不会将参数拼接到地址栏上

1 get请求传参(其中第三种比较常用)

方式1:直接传参

axios.get(‘http://localhost:3000/axios?id=123’).then(function(ret){

console.log(ret.data)

})

方式2:利用Restful形式进行传参

axios.get(‘http://localhost:3000/axios/123’).then(function(ret){

console.log(ret.data)

})

方式3:

axios.get(‘http://localhost:3000/axios’, {

params: {

id: 789

}

}).then(function(ret){

console.log(ret.data)

})

2 post传参

方式1:传递的是传统的json对象的字符串

axios.post(‘http://localhost:3000/axios’, {

uname: ‘lisi’,

pwd: 123

}).then(function(ret){

console.log(ret.data)

})

方式2:post传参URLSearchParams() 传统的表单形式

var params = new URLSearchParams();

params.append(‘uname’, ‘zhangsan’);

params.append(‘pwd’, ‘111’);

axios.post(‘http://localhost:3000/axios’, params).then(function(ret){

console.log(ret.data)

})

3 put请求

axios put 请求传参

axios.put(‘http://localhost:3000/axios/123’, {

uname: ‘lisi’,

pwd: 123

}).then(function(ret){

console.log(ret.data)

})

4 delete请求

axios.delete('http://localhost:3000/axios', {

params: {

id: 111

}

}).then(function(ret){

console.log(ret.data)

})

Logo

前往低代码交流专区

更多推荐