index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>列表</title>
<!-- Latest compiled and minified CSS -->
<link
rel="stylesheet"
href="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"
/>
</head>
<body class="container">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">萌宠列表</h3>
</div>
<div class="panel-body">
<a href="/new.html" class="btn btn-danger btn-sm">新增</a>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>序号</th>
<th>头像</th>
<th>名称</th>
<th>技能</th>
<th>操作</th>
</tr>
</thead>
<tbody id="list"></tbody>
</table>
</div>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.min.js"></script>
<script>
axios.get("/api/v1/pets").then((res) => {
var strHtml = "";
res.data.forEach((pet, index) => {
strHtml += `<tr>
<td>${
index + 1}</td>
<td>${
pet.name}</td>
<td><img src="${
pet.img
}" style="width: 80px; max-height: 80px;"/></td>
<td>${
pet.skills}</td>
<td>
<button onclick="delOne('${
pet.id
}')" class="btn btn-danger btn-sm">删除</button>
<a class="btn btn-info btn-sm" href="/edit.html?id=${
pet.id
}">修改</a>
</td>
</tr><