vue.js 前端 前端框架 开发语言 网页制作神器—ElementUI(小白入门超详细) - // ***/manager/files/1697438073596-avatar
:el-menu的子元素用来定义el-menu点击列表的列表名字。
:按钮元素,菜单列表的单位元素。
:el-men-item的分组元素。
四、总结element组件(可复制直接使用)
下拉选择框
data() {
return {
list: [],
}
}
this.$request.get('/xxx/selectAll', {
params: {
}
}).then(res => {
this.list = res.data
})
文件、图片上传展示
:action="$baseUrl + '/files/upload'"
:headers="{ token: user.token }"
list-type="picture"
:on-success="handleImgSuccess"
>
上传
handleImgSuccess(response, file, fileList) {
this.form.img = response.data
},
// 表格显示 图片
// 表格显示 下载
日期时间
v-model="form.date" style="width: 100%">
v-model="form.time" style="width: 100%">
单选
表单校验
rules: {
username: [
{ required: true, message: '请输入账号', trigger: 'blur' },
{ min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
],
confirmPass: [
{ validator: validateConfirmPass, trigger: 'blur' }
]
}
let validateConfirmPass = (rule, value, callback) => {
if (value === '') {
callback(new Error('请再次输入密码'));
} else if (value !== this.form.password) {
callback(new Error('两次输入密码不一致!'));
} else {
callback();
}
}
只能输入整数
num: [
{ required: true, message: '请输入整数', trigger: 'blur' },
{ pattern: /^[1-9]\d*$/, message: '只能输入正整数',}
]
审核
changeStatus(row, status) {
this.form = JSON.parse(JSON.stringify(row))
this.form.status = status
this.$confirm('您确定'+status+'吗?', '确认审核', {type: "warning"}).then(response => {
this.$request.put('/xxx/update', this.form).then(res => {
if (res.code === '200') {
this.$message.success('审核成功')
this.load(1)
} else {
this.$message.error(res.msg) // 弹出错误的信息
}
})
}).catch(e => {})
},
表格显示高亮信息
表格里显示图片
表格里显示视频
评分 ⚽
data() {
return {
star: 5
}
}
树形下拉菜单
v-for="item in departmentList"
:key="item.id"
:value="item.id"
:label="item.name"
style="display: none;"/>
:data="departmentTree"
:props="{children: 'children', label: 'name'}"
highlight-current
@node-click="handleNodeClick"
default-expand-all />
created() {
// 先查出扁平的部门数组
this.$request.get('/department/selectAll').then(res => {
this.departmentList = res.data
})
// 再查出树形的部门数组
this.$request.get('/department/selectTree').then(res => {
this.departmentTree = res.data
})
}
// node 就是department对象
handleNodeClick(node) {
this.$set(this.form, 'departmentId', node.id)
this.$refs.selectTree.blur()
},
Switch切换按钮
轮播图
时间线 參
{{ item.content }}
下拉多选 ✉️
创建属性 tags
tags: []
在编辑的时候 注意把保存的JSON字符串转成JSON数组
this.tags = JSON.parse(this.form.tags || '[]')
在保存的时候把JSON数组转成JSON字符串存到数据库
this.form.tags = JSON.stringify(this.tags) // 把数组转成JSON字符串存储
富文本
安装:
npm i wangeditor --save
页面导入 :
import E from "wangeditor"
setRichText(html) {
this.$nextTick(() => {
this.editor = new E(`#editor`)
this.editor.config.uploadImgServer = this.$baseUrl + '/files/editor/upload'
this.editor.config.uploadFileName = 'file'
this.editor.config.uploadImgHeaders = {
token: this.user.token
}
this.editor.config.uploadImgParams = {
type: 'img',
}
this.editor.config.zIndex = 0
this.editor.create() // 创建
this.editor.txt.html(html)
})
},
新增和编辑设置富文本
handleAdd() { // 新增数据
this.form = {} // 新增数据的时候清空数据
this.fromVisible = true // 打开弹窗
this.setRichText('')
},
handleEdit(row) { // 编辑数据
this.form = JSON.parse(JSON.stringify(row)) // 给form对象赋值 注意要深拷贝数据
this.fromVisible = true // 打开弹窗
this.setRichText(this.form.content)
},
/** 拼多多帮助力入口
* 富文本文件上传
*/
@PostMapping("/editor/upload")
public Dict editorUpload(MultipartFile file) {
String flag;
synchronized (FileController.class) {
flag = System.currentTimeMillis() + "";
ThreadUtil.sleep(1L);
}
String fileName = file.getOriginalFilename();
try {
if (!FileUtil.isDirectory(filePath)) {
FileUtil.mkdir(filePath);
}
// 文件存储形式:时间戳-文件名
FileUtil.writeBytes(file.getBytes(), filePath + flag + "-" + fileName); // ***/manager/files/1697438073596-avatar.png
System.out.println(fileName + "--上传成功");
} catch (Exception e) {
System.err.println(fileName + "--文件上传失败");
}
String http = "http://" + ip + ":" + port + "/files/";
return Dict.create().set("errno", 0).set("data", CollUtil.newArrayList(Dict.create().set("url", http + flag + "-" + fileName)));
}
注意:在save的时候设置变量值
this.form.content = this.editor.txt.html()
预览
变量
editor: null,
content: '',
fromVisible1: false,
表格
函数
preview(content) {
this.content = content
this.fromVisible1 = true
},
表单
推荐阅读
返回顶部暗黑模式