vue config js在本地可以正常运行,但不能在生产环境中使用

时间:2020-07-14 19:28:14

标签: javascript vue.js

当我在本地服务器上进行API调用时,效果很好,但是在Heroku部署的应用程序上却不断收到404错误。

config.js文件

module.exports = {
  devServer: {
    proxy: {
      '/api': {
        target: 'https://simple-order-api.herokuapp.com',
      },
    },
  },
};

store / index.js文件

Vue.use(Vuex);

export default new Vuex.Store({
  strict: true,
  state: {
    baseUrl: '/api',
  },
});

auth.js文件

  actions: {
    register({ commit, state }) {
      commit('setRegisterError', null);
      return HTTP().post('/auth/register', {
        email: state.registerEmail,
        password: state.registerPassword,
      })
        .then(({ data }) => {
          commit('setToken', data.token);
          router.push('/');
        })
        .catch(() => {
          commit('setRegisterError', 'An error occured while creating your account');
        });
    },
};

0 个答案:

没有答案