javascript - "No data available in table"VueJS

标签 javascript jquery vue.js datatables vuejs2

我正在构建一个实时网络应用程序。服务器运行在 Node.js 上,客户端使用 VueJS 编写。我编写了一个 API 来获取玩家信息。当我到达 REST 端点时,数据会以表格的形式显示。虽然数据显示正确,但第一行显示“表中没有可用数据”。

Picture

这是我的代码

import urlMixin from "./../mixins/url.js";

export default {

    data() {
        return {
            playerData: "",
            errors:[]
        }
    },

    created: function(){
        this.getAllPlayers();
    },

    mixins: [urlMixin],

    methods: {
        getAllPlayers: function(){
            axios.get(`${this.url}/players`)
            .then(response =>{
                console.log(response.data.results);

                this.playerData = response.data.results;

                for(let i=0; i<this.playerData.length;i++){
                    this.playerData[i].image = 
                        "data:image/jpeg;base64," +
                        btoa(
                            new Uint8Array(this.playerData[i].image.data).reduce(
                                (data, byte) => data + String.fromCharCode(byte),
                                ""
                        )
                    );
                }

            })
            .catch(e => {
                this.errors.push(e);
            });
        }
    },

    mounted() {

        $(function() {
            $('#player-table').DataTable({
                dom: '<"ui center aligned"f><"ui segment"t><"right-aligned-panel"p>',
                language: {
                    info: "",
                    paginate: {
                        first: "first",
                        previous: "<i class='fa fa-chevron-left'></i>",
                        next: "<i class='fa fa-chevron-right'></i>",
                        last: "last"
                    }
                }
            });

        });

    }
}
<style scoped>
    .bread-segment {
        margin-bottom: 10px;
        background: none;
        box-shadow: none;
        border: none;
    }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<template>
	<div class="ui center aligned animated fadeIn" style="padding:20px;">
		<table id="player-table" class="ui small table selectable " cellspacing="0" width="100%">
				<thead>
					<tr>
                        <th>Photo</th>
                        <th>Name</th>
						<th>Age</th>
						<th>Sex</th>
					</tr>
				</thead>
				
				<tbody>
					<tr v-for="playerInfo in playerData">
						<td><img class="ui mini rounded image" :src="playerInfo.image"></td>
                  
                        <td><a :href="'#/profile?name='+playerInfo.fname+'%20'+playerInfo.lname">{{playerInfo.fname}} {{playerInfo.lname}}</a></td>
                        
						<td>{{playerInfo.age}}</td>
						<td>{{playerInfo.sex}}</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</template>

我做错了什么?如何确保不会出现“表中没有可用数据”文本?

最佳答案

您正在同时使用 jQuery、DataTables 和 Vue。虽然这是可能做到的,但这些库的生命周期功能必然会产生干扰。

vue社区有几个表库如https://github.com/matfish2/vue-tables-2

关于javascript - "No data available in table"VueJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49680516/

相关文章:

javascript - js Tabulator 在复选框选择时触发事件 vue3js

javascript - 如果我使用 CLI3,如何更新 VueJs 中的文件路径

javascript - 如何增加 ionic 列表的宽度?

javascript - 可手动设置百分比格式的前导小数点

javascript - HTML:如何摆脱重叠

javascript - 使用 vue 组件时避免直接修改 prop

javascript - 如何根据选择将按钮发送到背景/禁用它们?

javascript - 在滚动了这么多 div 之后锁定屏幕上的 div?

php - 让 Javascript 与 PHP 对话

javascript - 单击侧边菜单导航 div 以外的按钮时如何关闭此侧边菜单导航