学习axios记录

1.引入axios依赖

 <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

2.发送get请求案例

3.发送带参数请求

综合案例

<!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="vue.js"></script>
</head>

<body>
    <!-- 引入axios依赖 -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

    <div id="app">

        文章分类: <input type="text" v-model="searchConditions.category">

        发布状态: <input type="text" v-model="searchConditions.state">

        <button @cick="search">搜索</button>

        <br />
        <br />
        <table border="1 solid" colspa="0" cellspacing="0">
            <tr>
                <th>文章标题</th>
                <th>分类</th>
                <th>发表时间</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            <tr v-for="(item,index) in articleList">
                <td>{{item.title}}</td>
                <td>{{item.category}}</td>
                <td>{{item.time}}</td>
                <td>{{item.state}}</td>
                <td>
                    <button>编辑</button>
                    <button>删除</button>
                </td>
            </tr>
            <!-- <tr>
                <td>标题2</td>
                <td>分类2</td>
                <td>2000-01-01</td>
                <td>已发布</td>
                <td>
                    <button>编辑</button>
                    <button>删除</button>
                </td>
            </tr>
            <tr>
                <td>标题3</td>
                <td>分类3</td>
                <td>2000-01-01</td>
                <td>已发布</td>
                <td>
                    <button>编辑</button>
                    <button>删除</button>
                </td>
            </tr> -->
        </table>
    </div>

    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                articleList: [],
                searchConditions: {
                    category: '',
                    state: ''
                },

            },
            method: {
                search: function () {
                    axios.get("http://localhost:8080/article/search?category=", 
                    this.searchConditions.category + "&state=" + this.state).then(
                        result => {
                            this.articleList = result.data;
                        }
                    ).catch(
                        err => {
                            console.log(err);
                        }
                    );
                }
            },
            mounted: function () {
                axios.get("http://localhost:8080/article/getAll").then(result => {
                    this.articleList = result.data;
                }).catch(err => {
                    console.log(err);
                });

            }
        })
    </script>
</body>

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值