目录
前言
BookList.vue
action.js
展示效果
前言
本篇还是在之前的基础上,继续完善功能。上一篇完成了数据表格的查询,这一篇完善增删改,以及表单验证。
BookList.vue
查询
新增
编辑
删除
export default {
data() {
return {
bookname: '',
tableData: [],
page: 1,
rows: 10,
total: 0,
title: '新增窗口',
dialogFormVisible: false,
formLabelWidth: '100px',
types: [],
book: {
id: '',
bookname: '',
price: '',
booktype: ''
},
rules: {
bookname: [{
required: true,
message: '请输入书籍名称',
trigger: 'blur'
}, ],
price: [{
required: true,
message: '请输入书籍价格',
trigger: 'blur'
}, ],
b服务器托管网ooktype: [{
required: true,
message: '请选择书籍类别',
trigger: 'blur'
}, ]
}
}
},
methods: {
// 删除
handleDelete(idx, row) {
this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let url = this.axios.urls.BOOK_DEL;
this.axios.post(url, {
id: row.id
}).then(r => {
console.log(r);
this.query({});
}).catch(e => {
});
this.$message({
type: 'success',
message: '删除成功!'
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
},
// 确认新增
dosub() {
this.$refs['book'].validate((valid) => {
if (valid) {
let url = this.axios.urls.BOOK_ADD;
if (this.title == '编辑窗口') {
url = this.axios.urls.BOOK_UPD;
};
let params = {
id: this.book.id,
bookname: this.book.bookname,
price: this.book.price,
booktype: this.book.booktype
};
this.axios.post(url, params).then(r => {
console.log(r);
this.clear();
this.query({});
}).catch(e => {
});
} else {
console.log('error submit!!');
return false;
}
});
},
// 初始化窗口
clear() {
this.dialogFormVisible = false;
this.title = '新增窗口',
this.book = {
id: '',
bookname: '',
price: '',
booktype: ''
}
},
// 打开窗口的方法
open(idx, row) {
this.dialogFormVisible = true;
// console.log(idx);
// console.log(row)
if (row) {
this.title = '编辑窗口';
this.book.id = row.id;
this.book.bookname = row.bookname;
this.book.price = row.price;
this.book.booktype = row.booktype;
}
},
// 当前页大小
handleSizeChange(r) {
let params = {
bookname: this.bookname,
rows: r,
page: this.page
}
this.query(params);
// 当前页码
},
handleCurrentChange(p) {
let params = {
bookname: this.bookname,
rows: this.rows,
page: p
}
this.query(params);
},
query(params) {
let url = this.axios.urls.BOOK_LIST;
this.axios.get(url, {
params: params
}).then(r => {
console.log(r);
this.tableData = r.data.rows;
this.total = r.data.total;
}).catch(e => {
});
},
onSubmit() {
let params = {
bookname: this.bookname
}
this.query(params);
}
},
created() {
this.query({});
this.types = [{
id: 1,
name: '玄幻'
}, {
id: 2,
name: '武侠'
}, {
id: 3,
name: '言情'
}, {
服务器托管网 id: 4,
name: '推理'
}, {
id: 5,
name: '恐怖'
}];
}
}
action.js
/**
* 对后台请求的地址的封装,URL格式如下:
* 模块名_实体名_操作
*/
export default {
'SERVER': 'http://localhost:8080', //服务器
'SYSTEM_USER_DOLOGIN': '/user/userLogin', //登陆
'SYSTEM_USER_DOREG': '/user/userRegister', //注册
'SYSTEM_MENUS': '/module/queryRootNode', //左侧菜单树
'BOOK_LIST': '/book/queryBookPager', //数据表格
'BOOK_ADD': '/book/addBook', //数据增加
'BOOK_UPD': '/book/editBook', //数据修改
'BOOK_DEL': '/book/delBook', //数据删除
'getFullPath': k => { //获得请求的完整地址,用于mockjs测试时使用
return this.SERVER + this[k];
}
}
展示效果
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
变量 # 打印 print(123) # 变量就是专门用来保存数据的,关键词不能用于变量 # 赋值给变量num num = 123 # 打印 # 123 print(num) # 还可用于计算 new_num = num + 2 # 打印结果 # 123 pr…