基于 Vue 的 axios 客户端与 php 后端通信存在问题

问题描述 投票:0回答:1

规格如下: 我用路由器和简单的 php 测试后端制作了前端 vue 网站。 构建后的文件夹结构如下所示:

public_html_
├── css
├── js
├── favicon.ico
├── index.html
├── style.css
├── .htaccess
└── lipton
    └── index.php

然后我使用 litespeed img 创建 docker 来为应用程序提供服务。 public_html 形式的所有元素都将转到 /var/www/vhosts/localhost/html/ 为了修复路由器,我添加了 .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\\.html$ - [L]
RewriteRule ^lipton - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

打开页面后我想通过这个fn“登录”但失败了

const callApi = async () => {
  const url = 'localhost/lipton/'
  try {
    const response = await axios.post(url, {
      username: login.value,
      password: password.value
    });
    console.log(response.data);
  } catch (error) {
    console.error('Error occured:', error);
  }
};

// respose content
<!doctype html>
<html lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <link rel="icon" href="favicon.ico">
        <link rel="stylesheet" href="./style.css">
        <script defer="defer" src="js/chunk-vendors.c9dd1c52.js"></script>
        <script defer="defer" src="js/app.89866d1c.js"></script>
        <link href="css/app.1defc4ab.css" rel="stylesheet">
    </head>
    <body>
        <noscript>
            <strong>We're sorry but aleksandra_zalinska doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
        </noscript>
        <div id="app"></div>
    </body>
</html>

当我使用邮递员时,我收到 {"message":"Login success"} 所以 php 后端显然工作正常。 可能是什么问题?

php vue.js apache axios litespeed
1个回答
0
投票

可能您必须将

const url = 'localhost/lipton/'
更改为
const url = 'http://localhost/lipton/'

© www.soinside.com 2019 - 2024. All rights reserved.