当我尝试将某些内容发布到我的api时,我的“跨域请求”出现了相同的来源

时间:2019-06-21 12:23:05

标签: api vue.js request cross-domain

所以我创建了一个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;
              });
       }
   },
}

0 个答案:

没有答案