Please Help me, How to post data using the request which made by Vue.js
There's Vue
's code
let tests = {
cat1: {
name: 'Auth',
items: {
authorize2: {
name: 'Successful',
subname: '',
request: {
method: 'POST',
link: 'auth',
data: {
login: 'admin',
password: 'password'
}
},
test: (result, status) => {
if (status.status == 200) {
return true;
}
return false;
}
}}}}
PHP page which receives this code doesn't have anything in POST data storage.
Originally Vue used the vue-resource package to perform POST requests via the $http instance property:
login(){
var data = {
login: 'admin',
password: 'password'
}
this.$http.post('/auth', data)
.then(response => { /* success callback */ }, response => { /* error callback */ })
}
In Vue2 vue-resource was retired and they started to recommend Axios. They also offered a way to override the $http instance property allowing you to invoke the axios library in a similar way.
this.$http.post('/auth', data)
.then(response => { /* success callback */ })
.catch(error => { /* error callback */ })
Or you can just load the Axios Package and call it directly:
const axios = require('axios');
...
axios.post('/auth', data)
.then(response => { /* success callback */ })
.catch(error => { /* error callback */ })
You could even choose to use vanilla js or another library like jQuery and use $.ajax() to make the request within your Vue instance, but using axios is the current recommendation from Vue.