【发布时间】:2021-10-13 13:17:18
【问题描述】:
我正在尝试在 vue js 中使用 jquery 数据表,但是当我更改“显示条目”或在“搜索”中输入内容时,不会显示任何记录 任何提示我做错了什么(我对 Vue Js 不是很有经验)将不胜感激 下面的代码(从一个例子中得到,它似乎可以加载表中的数据):
template>
<div class="Example">
<h2>Implement jQuery DataTable in Vue Js</h2>
<table class="display table-bordered nowrap" cellspacing="0" width="100%" id="datatable">
<thead>
<tr>
<th>ID</th>
<th>Product Title</th>
<th>Product Price</th>
<th>Created On</th>
</tr>
</thead>
<tbody>
<tr v-for="item in products" :key="item.id">
<td>{{item.id}}</td>
<td>{{item.product_title}}</td>
<td>{{item.product_price}}</td>
<td>{{item.created_at}}</td>
</tr>
</tbody>
</table>
</div>
</template>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script>
import 'jquery/dist/jquery.min.js';
import 'bootstrap/dist/css/bootstrap.min.css';
import 'datatables.net-dt/js/dataTables.dataTables'
import 'datatables.net-dt/css/jquery.dataTables.min.css'
import axios from 'axios';
import $ from 'jquery';
export default {
mounted(){
axios
.get("https://www.testjsonapi.com/products/")
.then((response)=>
{
this.products = response.data;
$('#datatable').DataTable();
})
},
data: function() {
return {
products:[]
}
},
}
</script>
【问题讨论】: