释放双眼,带上耳机,听听看~!
要传递的参数是:
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