规格如下: 我用路由器和简单的 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 后端显然工作正常。 可能是什么问题?
可能您必须将
const url = 'localhost/lipton/'
更改为 const url = 'http://localhost/lipton/'