axios前后端通信,前端页面展示程序

在html页面做了一个axios通信的程序,界面程序如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>前后端通信</title>
<!--    引入相应的js文件-->
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style type="text/css">
        * {
            margin: 0px;
            padding: 0px;
        }
        .button{
            width: 60px;
            line-height: 25px;
            text-align: center;
            font-weight: bold;
            color: #fff;
            text-shadow:1px 1px 1px #333;
            border-radius: 5px;
            margin:0 20px 20px 0;
            position: relative;
            overflow: hidden;
        }
        table.gridtable {
            font-family: verdana,arial,sans-serif;
            font-size:11px;
            color:#333333;
            border-width: 1px;
            border-color: #666666;
            border-collapse: collapse;
        }
        table.gridtable th {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #666666;
            background-color: #dedede;
        }
        table.gridtable td {
            border-width: 1px;
            padding: 8px;
            border-style: solid;
            border-color: #666666;
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div id="app">
    <div>
        <h1>用户信息表</h1>
        <table class="gridtable">
            <tr>
                <th>ID</th><th>名称</th><th>电话</th>
            </tr>
            <tr v-for="item in shu">
                <td>{{item.id}}</td><td>{{item.name}}</td><td>{{item.phone}}</td>
            </tr>

        </table>
    </div>
    <div>
        <label>第</label>
        <select name="page" id="pid">
            <option>1</option>
            <option>2</option>
            <option>3</option>
        </select>
        <label>页</label>
        <label >每页显示</label>
        <select name="pagesize" id="psd">
            <option>1</option>
            <option>2</option>
            <option>3</option>
        </select>
        <label >条数</label>
        <br>
        <button @click="btnclidk" class="button">提交</button>
    </div>

</div>

<script type="text/javascript">
    var app = new Vue({
        el:"#app",
        data:{
            shu:"",
        },
        methods:{
            btnclidk:function (ev) {
                var pag =$("#pid").val();//第几页
                var pagesiz=$("#psd").val();//每页显示条数
                axios.post("请求路径",{"pageSize":pagesiz,"page":pag}).then(res=>{
                 
                    this.shu=res.data.listData;
                }).catch(err=>{
                    console.log(err);
                })
            }
        }
    })
</script>
</body>
</html>

只需在路径处添加自己项目的路径,然后修改相应的json数值,即可进获得后端的数据,页面如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值