【问题标题】:PHP with Vue CLI how to set vue.config.jsPHP 与 Vue CLI 如何设置 vue.config.js
【发布时间】:2022-01-14 10:22:35
【问题描述】:

尝试将 PHP 与 Vue CLI 一起使用,我正在尝试复制: https://forum.vuejs.org/t/using-php-with-vue-cli/52842/3 但失败了。

我有这个文件夹结构:

  1. 我的应用程序/

    • 公开/
    • src/
    • vue.config.js
  2. 返回/

    • index.php

当我从 myapp/ 运行 npm run serve 时,我会转到 http://localhost:8080 并查看我的应用程序。

在另一个名为“back”的文件夹中,我有我的 php 文件。 我使用 mamp 运行服务器,并通过以下地址访问此文件夹:http://back:8888

在我的 vue.config.js 中有

module.exports = {
  devServer: {
    proxy: {
      '^/api': {
        target: 'http://back:8888',
        changeOrigin: true,
        logLevel: "debug"
      }
    }
  }
};

据我了解,当我访问 http://localhost:8080/api 和 http://back:8888 时应该有相同的页面。

但我没有,我得到了 http://localhost:8080/api 的 404,然后返回:8888 就可以了。

在终端我有这个[HPM] GET /api -> http://back:8888 所以它确实检测到重定向。

最奇怪的是:

module.exports = {
  devServer: {
    proxy: {
      '^/api': {
        target: 'http://back:8888/index.php',
        changeOrigin: true,
        logLevel: "debug"
      }
    }
  }
};

当我访问 localhost:8080/api 时,我的后台文件夹中确实有 index.php 的输出。

我在这里错过了什么?

谢谢

【问题讨论】:

    标签: php vue.js proxy


    【解决方案1】:

    我添加小姐阅读https://forum.vuejs.org/t/using-php-with-vue-cli/52842/3

    localhost:8080/api == http://back:8888/api,但不像我这样: localhost:8080/api == http://back:8888。

    【讨论】:

      猜你喜欢
      • 2020-02-08
      • 2019-12-17
      • 2021-07-10
      • 2019-03-25
      • 2018-12-05
      • 2020-03-12
      • 2020-04-22
      • 2021-12-26
      相关资源
      最近更新 更多