<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ajax</title>
</head>
<body>
<input type="button" value="获取数据" onclick="getData()">
<div id="div1"></div>
</body>
<script>
function getData() {
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("get", "http://www.baidu.com");
xmlHttpRequest.send();
xmlHttpRequest.onreadystatechange = function () {
if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
document.getElementById('div1').innerHTML = xmlHttpRequest.responseText;
}
}
}
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>axios</title>
<script src="../vue/axios.js"></script>
</head>
<body>
<input type="button" value="get请求" onclick="get()">
<input type="button" value="post请求" onclick="post()">
</body>
<script>
function get() {
axios({
method:"get",
url:"http://yapi.smart-xwork.cn/mock/169327/emp/list"
}).then(result=>{
console.log(result.data)
})
}
function post() {
axios({
method:"post",
url:"http://yapi.smart-xwork.cn/mock/169327/emp/deleteById",
data:"id=1"
}).then(result=>{
console.log(result.data)
})
}
</script>
</html>
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>axios表格</title>
<!-- <script src="../vue/axios.js"></script>-->
<!-- <script src="../vue/vue.js"></script>-->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
<table>
<tr>
<th>编号</th>
<th>姓名</th>
<th>图像</th>
<th>性别</th>
<th>职位</th>
<th>入职时间</th>
<th>最后操作时间</th>
</tr>
<tr v-for="(item,index) in emps">
<td>{{index+1}}</td>
<td>{{item.name}}</td>
<td><img v-bind:src="item.url"></td>
<td v-if="item.gender==1">男</td>
<td v-if="item.gender==2">女</td>
<td>{{item.job}}</td>
<td>{{item.entrydate}}</td>
<td>{{item.updatetime}}</td>
</tr>
</table>
</div>
<script>
new Vue({
el: "#app",
data: {
emps: [ ]
},
mounted()
{
axios.get("http://yapi.smart-xwork.cn/mock/169327/emp/list").then(result => {
this.emps = result.data.data;
})
}
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>axios表格</title>
<script src="../vue/axios.js"></script>
<script src="../vue/vue.js"></script>
<!--<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>-->
</head>
<body>
<div id="app">
<table>
<tr>
<th>编号</th>
<th>姓名</th>
<th>图像</th>
<th>性别</th>
<th>职位</th>
<th>入职时间</th>
<th>最后操作时间</th>
</tr>
<tr v-for="(item,index) in emps">
<td>{{index+1}}</td>
<td>{{item.name}}</td>
<td><img v-bind:src="item.url"></td>
<td v-if="item.gender==1">男</td>
<td v-if="item.gender==2">女</td>
<td>{{item.job}}</td>
<td>{{item.entrydate}}</td>
<td>{{item.updatetime}}</td>
</tr>
</table>
</div>
<script>
new Vue({
el: "#app",
data: {
emps: [ ]
},
mounted()
{
axios.get("http://yapi.smart-xwork.cn/mock/169327/emp/list").then(result => {
this.emps = result.data.data;
})
}
});
</script>
</body>
</html>