【问题标题】:Vue 3 + DataTables.net: Data table does not update on filteringVue 3 + DataTables.net:数据表在过滤时不更新
【发布时间】:2022-06-24 00:42:02
【问题描述】:

第一次打开 HomeView 时,数据表会填充数据,但在更改时,例如“显示 10 个条目”到“显示 25 个条目”,数据表为空,数据不再显示在表中。

注意:我不是在寻求其他数据表库的建议。

我在 main.ts 中导入以下库:

import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'datatables.net-dt/js/dataTables.dataTables'
import 'datatables.net-dt/css/jquery.dataTables.min.css'
import 'jquery/dist/jquery.min.js';

HomeView.vue(视图):

<template>
  <DataTable :dataSource="dataSource" />         
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import axios from 'axios'
import DataTable from '@/components/DataTable.vue'

const dataSource = ref([])

onMounted(async () => {
    const response = await axios.get("https://jsonplaceholder.typicode.com/users")
    dataSource.value = response.data
})
</script>

DataTable.vue(组件):

<template>
    <div>
        <h1>Title</h1>
        
        <table class="table table-hover table-bordered" id="example">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Email</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="entry in dataSource" :key="entry.id">
                    <td>{{entry.id}}</td>
                    <td>{{entry.name}}</td>
                    <td>{{entry.email}}</td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { onMounted, withDefaults } from 'vue'
import $ from 'jquery'; 

interface Props {
    dataSource: Array
}

withDefaults(defineProps<Props>(), {
    dataSource: Array
})

onMounted(() => {
    $('#example').DataTable()
})

</script>

【问题讨论】:

    标签: vue.js datatables vuejs3


    【解决方案1】:

    @robtot 你发现了吗?我也有同样的问题

    【讨论】:

    猜你喜欢
    • 2018-01-14
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 2021-10-07
    • 1970-01-01
    相关资源
    最近更新 更多