## 前言
* 这一节是重点内容,将向大家介绍如何在saber上使用原生ElementUI进行开发一个CRUD的完整模块
* 下一节则会为大家带来saber基于avue的json数据驱动的CRUD模块
* 开发效率会成倍提升,真正享受极速开发带来的乐趣
* 在开发之前,我们需要配置一下mock数据,根据接口返回所需的数据
## 配置菜单
1. 进入菜单管理模块
![](https://img.kancloud.cn/6e/2a/6e2abde2695f9fdcaf6414d749d594ab_1744x1170.png)
2. 新建测试模块
![](https://img.kancloud.cn/a4/15/a41514099460c96ba287cdd4ecc2851b_2340x1232.png)
![](https://img.kancloud.cn/6f/99/6f992abbd1d44fa5b3b6923ccc4590b6_2592x1066.png)
3. 新建测试模块的增、删、改、查按钮
![](https://img.kancloud.cn/9e/4f/9e4fb95060b69d54064f53b55fe0a959_2352x1226.png)
![](https://img.kancloud.cn/22/3a/223aa80a1c3cd24e550576cf45bb7e12_2284x1026.png)
![](https://img.kancloud.cn/84/39/8439580eaed4c733a54b00bf0ab0056b_2322x1186.png)
![](https://img.kancloud.cn/ad/a7/ada77be53bb1afb24e176f62102d88a5_2336x1200.png)
![](https://img.kancloud.cn/87/63/87639a9060ee350591058486b7d66310_2574x1342.png)
4. 进入角色管理模块,进行权限分配
![](https://img.kancloud.cn/eb/fd/ebfd2c2199f8f97ceb8a1cf76da3dd2a_2324x1252.png)
5. 这时刷新菜单我们便可以看到刚刚新增的菜单了
![](https://img.kancloud.cn/a9/db/a9db3c3e59892060c85c56ad476e3406_480x938.png)
## 配置mock
1. 创建blog.js的mock文件
~~~
import Mock from 'mockjs'
function getFakeList() {
const json = {code: 200, success: true, msg: '操作成功'};
const list = [];
list.push(
{
id: '1',
title: '博客标题1',
time: '2019.09.26',
content: '博客内容1',
},
{
id: '2',
title: '博客标题2',
time: '2019.09.26',
content: '博客内容2',
}
);
json.data = {
total: 10,
size: 10,
current: 1,
searchCount: true,
pages: 1,
records: list,
};
return json;
}
function getFakeDetail() {
const json = {code: 200, success: true, msg: '操作成功'};
json.data = {
id: '1',
title: '博客标题1',
time: '2019.09.26',
content: '博客内容1',
};
return json;
}
function fakeSuccess() {
return {code: 200, success: true, msg: '操作成功'};
}
export default ({mock}) => {
if (!mock) return;
Mock.mock(/\/api\/blade-desk\/blog\/list/, 'get', getFakeList);
Mock.mock(/\/api\/blade-desk\/blog\/detail/, 'get', getFakeDetail);
Mock.mock(/\/api\/blade-desk\/blog\/submit/, 'post', fakeSuccess);
Mock.mock(/\/api\/blade-desk\/blog\/remove/, 'post', fakeSuccess);
}
~~~
2. 前往index.js进行开启
![](https://img.kancloud.cn/97/f0/97f0ba5dbe51d536d3a79939cdb0ad14_798x728.png)
3. 创建blog.js的api文件
~~~
import request from '@/router/axios';
export const getList = (current, size, params) => {
return request({
url: '/api/blade-desk/blog/list',
method: 'get',
params: {
...params,
current,
size,
}
})
}
export const getDetail = (id) => {
return request({
url: '/api/blade-desk/blog/detail',
method: 'get',
params: {
id,
}
})
}
export const remove = (ids) => {
return request({
url: '/api/blade-desk/blog/remove',
method: 'post',
params: {
ids,
}
})
}
export const submit = (row) => {
return request({
url: '/api/blade-desk/blog/submit',
method: 'post',
data: row
})
}
~~~
4. 基础工作已经完毕,下面我们就开始编写一个基础的crud模块吧