मेरे पास एक कोड है जो सर्वर को डेटा भेजता है और मेरे पास एक फ़ंक्शन है
save(contentType, data, setResponse) {
axios({
method: 'POST',
data: data,
}).then((response) => {
setResponse(data.response);
}
यह मुझे अपरिभाषित प्रकार देता है। मैं इसे कैसे ठीक करूं?
1
Ox Ox
7 पद 2020, 23:42
2 जवाब
सबसे बढ़िया उत्तर
आपको data.response
के बजाय response.data
लिखना चाहिए क्योंकि वहां वेरिएबल response
data
नहीं है:
submitForm(contentType, data, setResponse) {
axios({
url: `${API_BASE_URL}`,
method: 'POST',
data: data,
}).then((response) => {
// Change it here...
setResponse(response.data);
}).catch((error) => {
setResponse(error.response);
})
}
1
Praveen Kumar Purushothaman
7 पद 2020, 23:54
प्रतिक्रिया उपयोग का उदाहरण।
axios.get('/user/12345')
.then(function (response) {
console.log(response.data);
console.log(response.status);
console.log(response.statusText);
console.log(response.headers);
console.log(response.config);
});
प्रतिक्रिया स्कीमा
{
// `data` is the response that was provided by the server
data: {},
// `status` is the HTTP status code from the server response
status: 200,
// `statusText` is the HTTP status message from the server response
statusText: 'OK',
// `headers` the HTTP headers that the server responded with
// All header names are lower cased and can be accessed using the bracket notation.
// Example: `response.headers['content-type']`
headers: {},
// `config` is the config that was provided to `axios` for the request
config: {},
// `request` is the request that generated this response
// It is the last ClientRequest instance in node.js (in redirects)
// and an XMLHttpRequest instance in the browser
request: {}
}
0
Ali Turki
7 पद 2020, 23:57
यह प्रश्न का उत्तर देने में कैसे मदद करता है?
– Praveen Kumar Purushothaman
7 पद 2020, 23:57
मैं देख रहा हूं कि उसने इसे पहले ही हल कर लिया है। बस मैं साझा कर रहा हूँ ताकि वह Axios प्रतिक्रिया स्कीमा को समझ सके
– Ali Turki
8 पद 2020, 00:00
हाँ, ठीक है...
– Praveen Kumar Purushothaman
8 पद 2020, 00:00
data.response
के बजायresponse.data
आज़माएं