网页设计-vue&axios-案例
·
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="js/vue.js"></script>
<script src="js/axios-0.18.0.js"></script>
</head>
<body>
<div id="app">
<table border="1" cellspacing="0" width="60%">
<tr>
<th>编号</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>成绩</th>
<th>等级</th>
</tr>
<tr v-for="(user,index) in users">
<th>{{index+1}}</th>
<th>{{user.name}}</th>
<th>{{user.age}}</th>
<th>
<span v-if="user.gender==1">男</span>
<span v-if="user.gender==2">女</span>
</th>
<th>{{user.score}}</th>
<th>
<span v-if="user.score>=90">优秀</span>
<span v-else-if="user.score>=80">良好</span>
<span style="color: red" v-else>及格</span>
</th>
</tr>
</table>
</div>
</body>
<script>
new Vue({
el: "#app",
data: {
users: [],
},
mounted() {
//发送异步请求,加载数据
axios
.get("https://m1.apifoxmock.com/m1/7256819-6984025-default/banji")
.then((result) => {
console.log(result.data);
this.users = result.data;
});
},
});
</script>
</html>

更多推荐


所有评论(0)