所以我创建了一个api,并在localhost:8080上启动了服务,然后在localhost:8081上启动了vue.js,然后尝试将vue.js连接到api,这是我的代码
headers: {
'Access-Control-Allow-Origin': '*',
},
我试图将其放在axios函数中,但这对我不起作用
脚本:
import axios from 'axios';
export default {
name: "register",
data() {
return {
username: '',
pseudo: '',
email: '',
password: ''
};
},
methods: {
submitinscription(e) {
e.preventDefault();
let currentObj = this;
axios.post('http://127.0.0.1:8080/api/user', {
headers: {
'Access-Control-Allow-Origin': '*',
},
username: this.username,
pseudo: this.pseudo,
email: this.email,
password: this.password
})
.then(function (response) {
currentObj.output = response.data;
})
.catch(function (error) {
currentObj.output = error;
});
}
},
}