VUE 结合 jquery.dataTables 使用

Vue 结合 DataTables 使用

前言

在公司的项目里表格渲染使用的是 DataTables,同时我想使用 Vue 来进行数据绑定。

使用

<!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="E:\03_资料\02_开发组件库\01_前端\01_jquery-3.7.0.js"></script>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="E:\03_资料\02_开发组件库\01_前端\03_jquery.dataTables.min.js"></script>
    <link rel="stylesheet" href="E:\03_资料\02_开发组件库\01_前端\02_jquery.dataTables.min.css">
</head>
<body>
    <div id="app">
        <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>姓名</th>
                    <th>电话</th>
                    <th>住址</th>
                    <th>年龄</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="item in allData">
                    <td>{{item.name}}</td>
                    <td>{{item.phone}}</td>
                    <td>{{item.address}}</td>
                    <td>{{item.age}}</td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
</html>
<script>
    $(function () {
            var oTable1 = $('#example')
                .dataTable({
                    "bAutoWidth": false,
                    "aoColumns": [null, null, null, null]
                });
        });
  const { createApp } = Vue
  createApp({
    data() {
      return {
        allData:[
                {'name': '王因','phone': '13457890923','address': '兰州西固','age': 20},
                {'name': '王因','phone': '13457890923','address': '兰州西固','age': 20},
                {'name': '王因','phone': '13457890923','address': '兰州西固','age': 20},
                {'name': '李丽','phone': '13457890923','address': '兰州西固','age': 20},
            ]
      }
    }
  }).mount('#app')
</script>

结语

以上是我关于 Vue 和 DataTables 结合使用的解决方案。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值