html vue 动态展示数据

vue axios 后台动态加载数据,表格循环展示,并绑定按钮,点击时触发对应事件从后台再读取数据再循环展示。
因为子表格也是动态生成的所以要注意为主表格动态绑定id,同时作为参数传入生成子表格的点击方法。

//主表格
<table class="table table-striped" id="tb">
  <tr>
    <td width="20">id</td>
    <td>名称</td>
    <td width="64">修改</td>
  </tr>
  <tr v-for="ehon in msg" :id="ehon.ehonid">
    <td @click="clickehon(ehon.ehonid)">{{ehon.ehonid}}</td>
    <td @click="clickehon(ehon.ehonid)">{{ehon.ehonname}}</td>
    <td><button type="button" class="btn btn-info">修改</button></td>
  </tr>
</table>

//子表格
<table class="table table-striped" id="subtb">
   <tr>
     <td>img</td>
     <td width="20">count</td>
     <td>name</td>
     <td>play</td>
   </tr>
   <tr v-for="subehon in submsg">
     <td>{{subehon.avatarPath}}</td>
     <td>{{subehon.classCount}}</td>
     <td>{{subehon.name}}</td>
     <td>{{subehon.filePath}}</td>
   </tr>
 </table>

//
<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>
<script> // 从后台取绘本
  var vue = new Vue({
    el: '#app',
    data: {
      msg: null,
      submsg: null
    },
    mounted: function () {
      this.getEhon()
    },
    methods: {
      getEhon: function () {
        var that = this;
        axios.get("https://kangqiaomingju.top/apis/books/getAllBooks")
          .then(function (response) {//返回类型为list<class>
            that.msg = response.data;
          }).catch(function (reason) {
            console.log("error");
          });
      },

      clickehon: function (eid) {
        var that = this;
        axios.get("https://kangqiaomingju.top/apis/books/getSubItemsByID",
          {
            params: {
              ehonid: eid
            }
          }
        )
          .then(function (response) {//返回类型为list<class>
            that.submsg = response.data;
          }).catch(function (reason) {
            console.log("error");
          });
      },
    }
  });
</script>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值