VueTable.vue 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div class="table">
  3. <div class="crumbs">
  4. <el-breadcrumb separator="/">
  5. <el-breadcrumb-item><i class="el-icon-tickets"></i> 表格</el-breadcrumb-item>
  6. <el-breadcrumb-item>VueDatasource</el-breadcrumb-item>
  7. </el-breadcrumb>
  8. </div>
  9. <div class="container">
  10. <div class="plugins-tips">
  11. vue-datasource:一个用于动态创建表格的vue.js服务端组件。
  12. 访问地址:<a href="https://github.com/coderdiaz/vue-datasource" target="_blank">vue-datasource</a>
  13. </div>
  14. <datasource language="en" :table-data="getData" :columns="columns" :pagination="information.pagination"
  15. :actions="actions"
  16. v-on:change="changePage"
  17. v-on:searching="onSearch"
  18. ></datasource>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. import axios from 'axios';
  24. import Datasource from 'vue-datasource';
  25. export default {
  26. data(){
  27. return {
  28. url: './static/datasource.json',
  29. information: {
  30. pagination:{},
  31. data:[]
  32. },
  33. columns: [
  34. {
  35. name: 'Id',
  36. key: 'id',
  37. },
  38. {
  39. name: 'Name',
  40. key: 'name',
  41. },
  42. {
  43. name: 'email',
  44. key: 'email',
  45. },
  46. {
  47. name: 'ip',
  48. key: 'ip',
  49. }
  50. ],
  51. actions: [
  52. {
  53. text: 'Click',
  54. class: 'btn-primary',
  55. event: (e, row)=>{
  56. row && this.$message('选中的行数: ' + row.row.id);
  57. }
  58. }
  59. ],
  60. query:''
  61. }
  62. },
  63. components: {
  64. Datasource
  65. },
  66. methods: {
  67. changePage(values) {
  68. this.information.pagination.per_page = values.perpage;
  69. this.information.data = this.information.data;
  70. },
  71. onSearch(searchQuery) {
  72. this.query = searchQuery;
  73. }
  74. },
  75. computed:{
  76. getData(){
  77. return this.information.data.filter((d) =>{
  78. if(d.name.indexOf(this.query) > -1){
  79. return d;
  80. }
  81. })
  82. }
  83. },
  84. beforeMount(){
  85. // 开发环境使用 easy-mock 数据,正式环境使用 json 文件
  86. if(process.env.NODE_ENV === 'development'){
  87. this.url = '/ms/table/source';
  88. };
  89. axios.get(this.url).then( (res) => {
  90. this.information = res.data;
  91. })
  92. }
  93. }
  94. </script>
  95. <style src="../../../static/css/datasource.css"></style>