axios——post传参

释放双眼,带上耳机,听听看~!

要传递的参数是:
username:'admin'
password:'111111'

方法一:    


1
2
3
4
5
6
7
8
9
10
11
1var params = new URLSearchParams();
2    params.append('username', username);
3    params.append('password', password);
4    this.$axios({
5            method: 'post',
6            url:url,
7            data:params
8    }).then((res)=>{
9            console.log(res);
10    });
11

方法二:


1
2
3
4
5
6
7
8
9
1import qs from 'qs';
2    let params=qs.stringify({
3        username:username,
4        password:password
5    });
6    this.$axios.post(url,params).then(res=>{
7        console.log(res);
8    })
9

axios请求的时候带上请求头 token验证
方法一:


1
2
3
1this.$axios.defaults.headers.common['Authorization']=token;
2this.$axios.get('http://localhost:8080/test/3')
3

方法二:


1
2
3
4
5
6
7
1let config={
2     Authorization:token
3}
4this.$axios.get('http://localhost:8080/test/3',{
5    headers: config,
6})
7

 

给TA打赏
共{{data.count}}人
人已打赏
安全运维

MySQL到MongoDB的数据同步方法!

2021-12-11 11:36:11

安全运维

Ubuntu上NFS的安装配置

2021-12-19 17:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索