vue使用ajax获取后台数据进行显示

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/vue.min.js"></script>
    <script src="/vue-resource.min.js"></script>
    <style>
        #th th{
            background-color: #50a9fa;
            color: aliceblue;
            font-size: large;
        }
    </style>
</head>
<body >
<div id="app" align="center">
    <input type="text" v-model="id">
    <input type="text" v-model="pname">
    <button @click="addData">添加数据</button>
    <table id="th" border="1"solid width="400px">
        <tr>
            <th>编号</th>
            <th>名称</th>
            <th>时间</th>
            <th>操作</th>
        </tr>
        <tr v-for="item in list ">
            <td>{{item.id}}</td>
            <td>{{item.name}}</td>
            <td>{{item.ctime}}</td>
            <td>
                <a href="javascript:void(0)" >删除</a>
            </td>
        </tr>
    </table>
</div>
<script>
    //vue的生命周期
    
    new Vue({
       el:'#app',
        data:{
           list:[]
        },
        //vue对象实例创建成功之后就会自动调用这个方法
        //如果你想写的方法在舒适化的时候就被调用的话就要要用到created这个
        created:function () {
          this.getlist();//这里定义这个方法,vue实例之后运行到这里就调用这个函数
        },
        methods:{
            getlist:function () {
                //请求服务器的api获取到品牌的数据列表
                this.$http.get('http://vueapi.ittun.com/api/getprodlist').then(function (response) {
                    //处理服务器异常信息提示
                    if(response.body.status!=0)
                    {
                        alert(response.body.message);
                        return ;
                    }
                    //处理正常的逻辑数据处理
                    this.list=response.body.message;
                    
                });
                

            }
            
        }
    });
</script>
</body>
</html>
  • 4
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值