gpt4 book ai didi

mysql - 环回应用程序错误 ERR_ABORTED 404(未找到)

转载 作者:行者123 更新时间:2023-11-29 09:37:15 28 4
gpt4 key购买 nike

我是环回新手。我正在尝试在网页中显示记录列表。我使用 mysql 作为后端。当我运行服务器时,它运行了 2 或 3 分钟,然后服务器关闭了连接。当我向本地主机网页发出请求时没有显示数据库。

这是 users.json 的代码。

{
"name": "users",
"plural": "User",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"username": {
"type": "string",
"required": true
},
"password": {
"type": "number",
"required": true
},
"createdAt": {
"type": "date",
"required": true
},
"updatedAt": {
"type": "date",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}

这是 datasource.json 文件。

{
"db": {
"name": "db",
"connector": "memory"
},
"users": {
"host": "localhost",
"port": 3306,
"url": "",
"database": "shoppingdatabase",
"password": "",
"name": "users",
"user": "root",
"connector": "mysql"
}
}

这是index.html代码。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
<script src=".../boot/server.js"></script>


</head>
<body id="UserApp">
<script>
const API = 'http://localhost:3000/api/User/';

let UserApp = new Vue({
el: '#UserApp',
data: {
users: [],
user: {
id: '',
username: '',
password: '',
createdAt: '',
updatedAt: '',
email: ''
}
},
created: function () {
this.getUsers();
},
methods: {
getUsers: function () {
fetch(API)
.then(res => res.json())
.then(res => this.users = res);
},
storeUser: function () {
let method;
console.log('storeCat', this.user);
// Handle new vs old
if (this.user.id === '') {
delete this.user.id;
method = 'POST';
} else {
method = 'PUT';
}
fetch(API, {
headers: {
'Content-Type': 'application/json'
},
method: method,
body: JSON.stringify(this.user)
})
.then(res => res.json())
.then(res => {
this.getUsers();
this.reset();
});
},
deleteCat: function (c) {
fetch(API + c.id, {
headers: {
'Content-Type': 'application/json'
},
method: 'DELETE'
})
.then(res => res.json())
.then(res => {
this.getUsers();
});

// call reset cuz the cat could be 'active'
this.reset();
},
editUser: function (c) {
/*
This line was bad as it made a reference, and as you typed, it updated
the list. A user may think they don't need to click save.
this.cat = c;
*/
this.user.id = c.id;
this.user.username = c.username;
this.user.password = c.password;
this.user.createdAt = c.createdAt;
this.user.updatedAt = c.updatedAt;
this.user.email = c.email;
},
reset: function () {
this.user.id = '';
this.user.username = '';
this.user.password = '';
this.user.createdAt = '';
this.user.updatedAt = '';
this.user.email = '';
}
}
});
</script>
<div>

<h1>User List</h1>
<table>
<thead>
<tr>
<th>Id</th>
<th>Username</th>
<th>Password</th>
<th>Created Date</th>
<th>Updated Date</th>
<th>Email Address</th>
<td>&nbsp;</td>
</tr>
</thead>
<tbody>
<tr v-for="user in users">
<td @click="editUser(user)" class="userItem" title="Click to Edit">{{user.username}}</td>
<td>{{uaer.id}}</td>
<td>{{uaer.username}}</td>
<td>{{uaer.password}}</td>
<td>{{uaer.createdAt}}</td>
<td>{{uaer.updatedAt}}</td>
<td>{{uaer.email}}</td>
<td @click="deleteUser(user)" class="deleteUser" title="Click to Delete">Delete</td>
</tr>
</tbody>
</table>

<form @submit.prevent="storeUser">
<p>
<label for="username">User Name</label>
<input type="text" id="username" v-model="user.username">
</p>
<p>
<label for="password">Password</label>
<input type="password" id="password" v-model="user.password">
</p>
<p>
<label for="createdAt">Created Date</label>
<input type="text" id="createdAt" v-model="user.createdAt">
</p>
<p>
<label for="updatedAt">Updated Date</label>
<input type="text" id="updatedAt" v-model="user.updatedAt">
</p>
<p>
<label for="email">Email </label>
<input type="text" id="email" v-model="user.email">
</p>
<input type="reset" value="Clear" @click="reset">
<input type="submit" value="Save User 🐱">
</form>
</div>



</body>
<html/>

这是我的项目结构

enter image description here

这是我运行应用程序时的屏幕截图。

enter image description here

最佳答案

你真的需要访问那个/server.js吗?尝试为您的模型创建单独的 Controller 。或者尝试根据您的需要创建模型。仅供引用 - https://loopback.io/doc/en/lb3/Defining-models.html

然后删除它 从你的html中

你实际上不需要那个/server.js。另外,根据您的项目结构,您也没有任何 boot/server.js 。你的“boot”文件夹中只有 2 个文件 1.root.js 2.authentication.js

关于mysql - 环回应用程序错误 ERR_ABORTED 404(未找到),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57311668/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com