SPA项目开发之动态树+数据表格+分页
1、动态树的渲染
- 后台数据
t_vue_user
t_vue_tree_node
t_vue_articles
- 动态生成NavMenu导航菜单(只支持2级菜单)
2.1 结构
<el-menu key="" index="">
<el-submenu>
<template slot="title">
<i class="el-icon-location"></i>
<span>导航一</span>
</template>
<template slot="title">分组一</template>
<el-menu-item route="">
实现代码
首先修改成动态的菜单
2.2 vue+element的el-menu组件实现路由跳转及当前项的设置
<el-menu router :default-active="$route.path">
<el-menu-item index="/company/userManager">用户管理</el-menu-item>
注1:要实现路由跳转,先要在el-menu标签上添加router属性,然后只要在每个el-menu-item标签内
的index属性设置一下url即可实现点击el-menu-item实现路由跳转。
注2:导航当前项,在el-menu标签中绑定 :default-active="$route.path",注意是绑定属性,
不要忘了加“:”,当$route.path等于el-menu-item标签中的index属性值时则该item为当前项。
注3:后台t_tree_node表有几个节点的url为空,则会导致几个节点样式会一致
2、elementui中的数据表格
1,数据表格
<template>
<div>
<!--列表-->
<el-table size="small" :data="listDate" border element-loading-text="拼命加载中" style="width: 100%;">
<el-table-column align="center" type="selection" width="60">
</el-table-column>
<el-table-column sortable prop="id" label="文章Id" width="300">
</el-table-column>
<el-table-column sortable prop="title" label="文章标题" width="300">
</el-table-column>
<el-table-column sortable prop="body" label="文章内容" width="300">
</el-table-column>
<!-- <el-table-column align="center" label="操作" min-width="300">
<template slot-scope="scope">
<el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
<el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>
</template>
</el-table-column> -->
</el-table>
</div>
</template>
<script>
export default{
data(){
return{
listDate:[]
};
},
//钩子函数
created() {
let url=this.axios.urls.SYSTEM_ARTICLE_LIST;
this.axios.post(url, this.ruleForm).then((response)=>{
console.log(response);
this.listDate=response.data.result;
}).catch(function(error) {
console.log(error);
});
}
}
</script>
<style>
</style>
3、elementui中的分页及查询
Articles.vue
<template>
<div>
<!-- 搜索筛选 -->
<el-form :inline="true" :model="formInline" class="user-search">
<el-form-item label="搜索:">
<el-input size="small" v-model="formInline.title" placeholder="输入文章标题"></el-input>
</el-form-item>
<el-form-item>
<el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
</el-form-item>
</el-form>
<!--列表-->
<el-table size="small" :data="listDate" border element-loading-text="拼命加载中" style="width: 100%;">
<el-table-column align="center" type="selection" min-width="1">
</el-table-column>
<el-table-column sortable prop="id" label="文章Id" min-width="1">
</el-table-column>
<el-table-column sortable prop="title" label="文章标题" min-width="3">
</el-table-column>
<el-table-column sortable prop="body" label="文章内容" min-width="5">
</el-table-column>
</el-table>
<!-- 分页条 -->
<!-- @size-change:当页码发生改变触发的事件-->
<!-- @current-change:当前页码发生改变触发的事件-->
<el-pagination style="margin-top: 20px;" @size-change="handleSizeChange" @current-change="handleCurrentChange"
:current-page="formInline.page" :page-sizes="[10, 20, 30, 50]" :page-size="100" layout="total, sizes, prev, pager, next, jumper"
:total="total">
</el-pagination>
</div>
</template>
<script>
export default {
data() {
return {
listDate: [],
formInline:{
page:1,
rows:10,
title:''
},
total:0
};
},
methods:{
handleSizeChange(rows) {
//页码大小发生改变触发的事件
//console.log("当前页大小:"+rows);
this.formInline.page = 1;
this.formInline.rows = rows;
this.search();
},
handleCurrentChange(page) {
//当前页码发生改变触发的事件
// console.log("当前页码:"+page)
this.formInline.page = page;
this.search();
},
doSearch(params){
let url = this.axios.urls.SYSTEM_ARTICLE_LIST;
this.axios.post(url, params).then((response) => {
console.log(response);
this.listDate = response.data.result;
this.total=response.data.pageBean.total;
}).catch(function(error) {
console.log(error);
});
},
search(){
this.doSearch(this.formInline);
}
},
//钩子函数
created() {
this.doSearch({});
}
}
</script>
<style>
</style>
结果页面