Add the axios component based on vue to solve the problem that the post parameter is null. vueaxios
Good. goods will be delivered below.
1. Install axios
npm install axios --save
2. Add the axios component
import axios from 'axios'axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';axios.defaults.baseURL = 'http://localhost:7878/zkview';Vue.prototype.$ajax = axios;
3. get request
testGet: function () { this.$ajax({ method: 'get', url: '/test/greeting', params: { firstName: 'Fred', lastName: 'Flintstone' } }).then(function (response) { console.log(response); }).catch(function (error) { console.log(error); });},
4. post request
TestPost: function () {var params = new URLSearchParams (); params. append ('name', 'Hello jdmc '); params. append ('id', '2'); this. $ ajax ({method: 'post', url: '/test/greeting2', data: params/data: {id: '3', name: 'abc '}}). then (function (response) {console. log (response );}). catch (function (error) {console. log (error );})}
5. Running result:
6. Note:
There are two methods to pass parameters when using the post method. One is the common method and the other is the json method. If the background accepts the common method, use the preceding method.
Common formed Mode
Var params = new URLSearchParams (); params. append ('name', 'Hello jdmc '); params. append ('id', '2'); data: params
Backend receiving parameters:
public Student greeting2(int id,String name) {
Json
data: {id: '3', name: 'abc'}
Backend receiving Parameters
public Object greeting2(@RequestBody Object student) {
The above article adds the axios component based on vue to solve the problem that the post parameter is null. It is all the content that I have shared with you. I hope you can provide a reference and support for the customer's house.