This time I will show you how to handle null parameters in post in vue. What are the things to pay attention to when handling null parameters in post in vue? The following is a practical case. Get up and take a look. Okay, the goods will be shipped below.
1, Installationaxiosnpm install axios --save
2. Add axios componentimport 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 requesttestGet: 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 requesttestPost: 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);
})
}
method. If the background accepts the normal method, then use the above method.
Ordinary formed wayvar params = new URLSearchParams();
params.append('name', 'hello jdmc你好');
params.append('id', '2');
data:params
public Student greeting2(int id,String name) {
data: {id: '3', name: 'abc'}
public Object greeting2(@RequestBody Object student) {
Recommended reading:
springmvc cannot accept parameters when axios sends a requestHow does vue axios interrupt the request when switching pages? accomplishThe above is the detailed content of How to deal with null parameters passed in post in Vue. For more information, please follow other related articles on the PHP Chinese website!