[英]Displaying Data From Ajax with Vue and Ant Design Table
I am new in Vue and still learning using it. 我是Vue的新手,仍然在学习使用它。 I've been following example from this page: https://vue.ant.design/components/table/ 我一直在此页面上关注以下示例: https : //vue.ant.design/components/table/
I'm trying to fetch data using json to be displayed using Antd Tables. 我正在尝试使用要使用Antd Tables显示的json来获取数据。
But I include the js and css manually using and . 但是我使用和手动添加了js和CSS。
The data calling is fine as i can see from the console logged. 正如我从记录的控制台中看到的那样,数据调用很好。 But the table is not displaying any records. 但是该表未显示任何记录。
I've been trying to code in here: https://jsfiddle.net/dedychaidir/yvr5o8Lk/4/ 我一直在尝试在这里进行编码: https : //jsfiddle.net/dedychaidir/yvr5o8Lk/4/
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ant-design-vue@1.3.13/dist/antd.css" />
<script src="https://unpkg.com/vue"></script>
<script src="https://cdn.jsdelivr.net/npm/ant-design-vue@1.3.13/dist/antd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-resource@1.5.1"></script>
<div id="app">
<template>
<a-table :columns="columns" :rowKey="record => record.login.uuid" :dataSource="data" :pagination="pagination" :loading="loading" @change="handleTableChange">
<template slot="name" slot-scope="name">
{{name.first}} {{name.last}}
</template>
</a-table>
</template>
</div>
And this is the script section: 这是脚本部分:
const columns = [{
title: 'Name',
dataIndex: 'name',
sorter: true,
width: '20%',
scopedSlots: {
customRender: 'name'
},
}, {
title: 'Gender',
dataIndex: 'gender',
filters: [{
text: 'Male',
value: 'male'
},
{
text: 'Female',
value: 'female'
},
],
width: '20%',
}, {
title: 'Email',
dataIndex: 'email',
}];
var app = new Vue({
el: "#app",
mounted: function() {
this.fetch();
},
data: function() {
return {
data: [],
pagination: {},
loading: false,
columns,
}
},
methods: {
handleTableChange(pagination, filters, sorter) {
console.log(pagination);
const pager = {
...this.pagination
};
pager.current = pagination.current;
this.pagination = pager;
this.fetch({
results: pagination.pageSize,
page: pagination.current,
sortField: sorter.field,
sortOrder: sorter.order,
...filters,
});
},
fetch(params = {}) {
this.loading = true;
this.$http.get('https://randomuser.me/api',{params:{results:"10"}}).then(response => {
json = JSON.parse(response.bodyText);
const pagination = {
...this.pagination
};
pagination.total = 200;
this.loading = false;
this.data = json.results;
this.pagination = pagination;
console.log(this.data);
}, response => {
console.log(response.body);
});
},
},
});
Please show me if there are some error or mistakes. 如果有任何错误或错误,请告诉我。
Thank you. 谢谢。
I made codesandbox for you with provided code and everything works. 我用提供的代码为您制作了codeandbox,一切正常。
https://codesandbox.io/embed/vue-template-pluqh https://codesandbox.io/embed/vue-template-pluqh
Not sure, but maybe you just need to remove first <template>
tag inside div#app
because its not neccessary 不确定,但是也许您只需要删除div#app
中的第一个<template>
标记,因为它不是必需的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.