Home >Web Front-end >JS Tutorial >How to deal with null parameters passed in post in Vue
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);
})
}
There are two ways to pass parameters when using the post method, one is the normal method, and the other is the
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) {
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
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!