• Spa项目开发(动态树&数据表格&分页)


    一、动态树

    LeftNav.vue

    router :default-active="$route.path"  default-active="2" class="el-menu-vertical-demo" background-color="#334157" text-color="#fff"
        active-text-color="#ffd04b" :collapse="collapsed">
       
       


         
       

       
         
         
         
           
            {{m2.treeNodeName}}
         

       

     

    二、数据表格

    在项目的src中创建views/sys目录,在此目录下创建Articles.vue文件

    文件里添加如下代码

    Articles.vue

    1. <template>
    2. <div>
    3. <!--列表-->
    4. <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
    5. element-loading-text="拼命加载中" style="width: 100%;">
    6. <el-table-column align="center" type="selection" width="60">
    7. </el-table-column>
    8. <el-table-column sortable prop="id" label="编号" width="100">
    9. </el-table-column>
    10. <el-table-column sortable prop="title" label="文章标题" width="100">
    11. </el-table-column>
    12. <el-table-column sortable prop="body" label="文章内容" width="300">
    13. </el-table-column>
    14. <el-table-column align="center" label="操作" min-width="100">
    15. <template slot-scope="scope">
    16. <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
    17. <el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>
    18. </template>
    19. </el-table-column>
    20. </el-table>
    21. </div>
    22. </template>
    23. <script>
    24. export default {
    25. name: 'Articles',
    26. data() {
    27. return {
    28. listData: {}
    29. }
    30. },
    31. created() {
    32. let url = this.axios.urls.SYSTEM_ARTICLE_LIST;
    33. this.axios.post(url, param).then(res => {
    34. console.log(res);
    35. this.listData = res.data.result;
    36. this.formInline.total = res.data.pageBean.total;
    37. }).catch(function(error) {
    38. console.log(error);
    39. });
    40. }
    41. }
    42. </script>

    router/index.js

    import Articles from '@/views/sys/Articles'
    1. {
    2. path: '/AppMain',
    3. name: 'AppMain',
    4. component: AppMain,
    5. children: [{
    6. path: '/LeftNav',
    7. name: 'LeftNav',
    8. component: LeftNav
    9. },
    10. {
    11. path: '/TopNav',
    12. name: 'TopNav',
    13. component: TopNav
    14. },
    15. {
    16. path: '/sys/Articles',
    17. name: 'Articles',
    18. component: Articles
    19. }
    20. ]
    21. }

     运行后

     

    三、分页

    Articles.vue

    1. <template>
    2. <div>
    3. <!-- 搜索筛选 -->
    4. <el-form :inline="true" :model="formInline" class="user-search">
    5. <el-form-item label="搜索:">
    6. <el-input size="small" v-model="formInline.title" placeholder="输入文章标题"></el-input>
    7. </el-form-item>
    8. <el-form-item>
    9. <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
    10. <el-button size="small" type="primary" icon="el-icon-plus" @click="handleEdit()">添加</el-button>
    11. </el-form-item>
    12. </el-form>
    13. <!--列表-->
    14. <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
    15. element-loading-text="拼命加载中" style="width: 100%;">
    16. <!-- <el-table-column align="center" type="selection" width="60">
    17. </el-table-column> -->
    18. <el-table-column align="center" sortable prop="id" label="编号" width="100">
    19. </el-table-column>
    20. <el-table-column sortable prop="title" label="文章标题" width="100">
    21. </el-table-column>
    22. <el-table-column sortable prop="body" label="文章内容" width="300">
    23. </el-table-column>
    24. <el-table-column align="center" label="操作" min-width="100">
    25. <template slot-scope="scope">
    26. <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
    27. <el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>
    28. </template>
    29. </el-table-column>
    30. </el-table>
    31. <!-- 分页条 -->
    32. <el-pagination style="margin-top: 20px;" @size-change="handleSizeChange" @current-change="handleCurrentChange"
    33. :current-page="formInline.page" :page-sizes="[10, 20, 30, 50]" :page-size="100"
    34. layout="total, sizes, prev, pager, next, jumper" :total="formInline.total">
    35. </el-pagination>
    36. </div>
    37. </template>
    38. <script>
    39. export default {
    40. name: 'Articles',
    41. data() {
    42. return {
    43. listData: {},
    44. formInline: {
    45. page: 1,
    46. rows: 10,
    47. total: 0,
    48. title: ''
    49. }
    50. }
    51. },
    52. created() {
    53. this.dosearch({});
    54. },
    55. methods: {
    56. handleSizeChange(rows) {
    57. console.log("当前页查询数量为:" + rows);
    58. this.formInline.page = 1;
    59. this.formInline.rows = rows;
    60. this.search();
    61. },
    62. handleCurrentChange(page) {
    63. console.log("当前页为:" + page);
    64. this.formInline.page = page;
    65. this.search();
    66. },
    67. dosearch(param) {
    68. let url = this.axios.urls.SYSTEM_ARTICLE_LIST;
    69. this.axios.post(url, param).then(res => {
    70. console.log(res);
    71. this.listData = res.data.result;
    72. this.formInline.total = res.data.pageBean.total;
    73. }).catch(function(error) {
    74. console.log(error);
    75. });
    76. },
    77. search() {
    78. this.dosearch(this.formInline);
    79. }
    80. }
    81. }
    82. </script>
    83. <style>
    84. </style>

     

  • 相关阅读:
    「运维有小邓」活动目录变更监控
    JavaScript基本语法、函数
    个人博客测试报告
    阿里妈妈API接口;item_search - 按关键字或网址搜索商品
    API集成测试:SpringBoot+Junit
    自定义安装Redhat8.6镜像:
    Springboot+Easyexcel将数据写入模板文件并导出Excel
    阿里云服务器介绍_优势及新手购买流程
    MySQL-创建、修改和删除表
    力扣2296.设计一个文本编辑器
  • 原文地址:https://blog.csdn.net/weixin_61523879/article/details/126826225