element-Ui遇到的一些问题点记录

简介

饿了么vue的ui框架

npm 安装

1
npm i element-ui -S

深层样式修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<style scoped lang="scss">
  .form {
    background-color: #fff;
    /deep/ .list{
      font-size: 18px;
    }
  }
</style>

scss文件中使用深度选择器/deep/报错 Expected selector解决方法
记得sass中使用/deep/没问题,但是在scss中使用/deep/报错了。
找到vue官网关于深度选择器是这样说的:

有些像 Sass 之类的预处理器无法正确解析 >>>。这种情况下你可以使用 /deep/ 或 ::v-deep 操作符取而代之——两者都是 >>> 的别名,同样可以正常工作。

于是用 ::v-deep 就可以了

::v-deep .el-checkbox__input{
display: none;
}

input的placeholder字体颜色

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.el-input__inner::placeholder {
color: #31E5F5;
}
/* 谷歌 */
.el-input__inner::-webkit-input-placeholder {
color: #31E5F5;
}
/* 火狐 */
.el-input__inner:-moz-placeholder {
color: #31E5F5;
}
/*ie*/
.el-input__inner:-ms-input-placeholder {
color: #31E5F5;
}

左侧菜单点击后菜单详情后,左侧菜单默认选中状态

:default-active=”activeMenu”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<el-scrollbar wrap-class="scrollbar-wrapper">
<el-menu
:default-active="activeMenu"
:collapse="isCollapse"
:background-color="variables.menuBg"
:text-color="variables.menuText"
:unique-opened="false"
:active-text-color="variables.menuActiveText"
:collapse-transition="false"
mode="vertical"
>
<sidebar-item v-for="route in permission_routes" :key="route.path" :item="route" :base-path="route.path" />
</el-menu>
</el-scrollbar>

详情页路由配置 activeMenu:’/organization/cysq’,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const organizationRouter = {
path: '/organization',
component: Layout,
redirect: '/organization/cygl',
// alwaysShow: true, // will always show the root menu
name: 'Permission',
meta: {
title: '组织管理',
icon: 'icon-a-zu315',
},
children: [
{
path: 'bmgl',
component: () => import('@/views/myView/organization/bmgl'),
name: 'bmgl',
meta: {
title: '部门管理',
// icon: 'icon-a-zu315',
search: true,
placeholder: '搜索场所',
},
},
{
path: 'cygl',
component: () => import('@/views/myView/organization/cygl'),
name: 'cygl',
meta: {
title: '成员管理',
// icon: 'icon-a-zu315',
search: true,
placeholder: '搜索场所',
},
},
{
path: 'cysq',
component: () => import('@/views/myView/organization/cysq'),
name: 'cysq',
meta: {
title: '成员申请',
// icon: 'icon-a-zu315',
search: true,
placeholder: '搜索姓名',
},
},
{
path: 'sqDetail',
component: () => import('@/views/myView/organization/sqDetail'),
name: 'sqDetail',
hidden: true,
meta: {
activeMenu:'/organization/cysq',
title: '申请详情',
// icon: 'icon-a-zu315',
// search: true,
back: true,
placeholder: '搜索场所',
},
},
]
}

菜单路由跳转

是否使用 vue-router 的模式,启用该模式会在激活导航时以 index 作为 path 进行路由跳转 <el-menu 里属性 router

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<el-menu
style="width: 290px;"
:default-active="activePath"
class="el-menu-vertical-demo"
bckground-color="#fff"
text-color="#333"
active-text-color="#4385F8"
:unique-opened="true"
router
@select="menuSelect">
<div v-for="(menu, index) in menuList" :key="index">
<el-submenu v-if="menu.children.length" :index="menu.index">
<template slot="title">
<img class="menu-icon-img" :src="activeClassAPath == menu.index ? menu.iconUrl : menu.defaultIconUrl" alt="">
<span class="menu-icon-name f-20 color-3" :style="{color: activeClassAPath == menu.index ? '#333' : '#333'}">{{menu.name}}</span>
</template>
<el-menu-item
v-for="(item, itemI) in menu.children"
:key="itemI"
:index="item.index" class="f-18">
<!-- <span class="identification" :class="activeClassAPath == item.index ? 'identification1':'identification'"></span> -->
{{item.name}}
</el-menu-item>
</el-submenu>
<el-menu-item v-else :index="menu.index">
<img class="menu-icon-img" :src="activePath == menu.index ? menu.iconUrl : menu.defaultIconUrl" alt="">
<span slot="title">{{menu.name}}</span>
</el-menu-item>
</div>
</el-menu>

是否使用 vue-router 的模式,启用该模式会在激活导航时以 index 作为 path 进行路由跳转

省市区三级联动

案例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
npm install element-china-area-data -S


import { provinceAndCityData, regionData, provinceAndCityDataPlus, regionDataPlus, CodeToText, TextToCode } from 'element-china-area-data'

provinceAndCityData是省市二级联动数据(不带“全部”选项)
regionData是省市区三级联动数据(不带“全部”选项)
provinceAndCityDataPlus是省市区三级联动数据(带“全部”选项)
regionDataPlus是省市区三级联动数据(带“全部”选项)
“全部"选项绑定的value是空字符串”"
CodeToText是个大对象,属性是区域码,属性值是汉字 用法例如:CodeToText[‘110000’]输出北京市
extToCode是个大对象,属性是汉字,属性值是区域码
用法例如:TextToCode[‘北京市’].code输出110000,TextToCode[‘北京市’][‘市辖区’].code输出110100,TextToCode[‘北京市’][‘市辖区’][‘朝阳区’].code输出110105

<template>
<div id="app">
<el-cascader
size="large"
:options="options"
v-model="selectedOptions"
@change="handleChange">
</el-cascader>
</div>
</template>

<script>
import { provinceAndCityData } from 'element-china-area-data'
export default {
data () {
return {
options: provinceAndCityData,
selectedOptions: []
}
},

methods: {
handleChange (value) {
console.log(value)
}
}
}
</script>


https://blog.csdn.net/xiejnpeng/article/details/111400199

dwy代码 案例




<el-cascader style="width: 100%;" :options="options" v-model="formZzxx.address"
@change="handleChange" filterable :props="{ value: 'label' }"
placeholder="省/市/区"></el-cascader>


import { regionData } from 'element-china-area-data'

// 组织信息
// 省市区
options: regionData,
formZzxx: {
address: ["山西省", "阳泉市", "矿区"],
},

handleChange(value) {
console.log('value', value);
}


el-cascader多级选择联动数据,配置value,lable

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
   <el-form-item
label="类型"
>
<el-cascader
v-model="form.flzj"
:options="flzjlist"
:props="defaultParams"
clearable
></el-cascader>
</el-form-item>

data() {
return {
//定义级联选择器的props
defaultParams: {
label: "dwmc",
value: "id",
children: "children",
checkStrictly: true
},
//级联样式选择器遍历的数组
flzjlist: [],
};
},

element组件文字切换中文模式

修改 src\main.js / locale: enLang // 如果使用中文,无需设置,请删除

1
2
3
4
Vue.use(Element, {
size: Cookies.get('size') || 'medium', // set element-ui default size
// locale: enLang // 如果使用中文,无需设置,请删除
})

样式修改代码

左侧菜单选中背景颜色父级

1
2
3
4
5
6
7
8
#app .sidebar-container .el-menu-item.is-active {
color: #fff !important;
background-color: #296DD8 !important;

.el-submenu__title i {
color: pink;
}
}

左侧菜单选中图标颜色父级

1
2
3
4
.is-active .el-submenu__title i {
color: #296DD8 !important;
}

左侧菜单选中背景颜色子集

1
2
3
#app .sidebar-container .el-submenu .el-menu-item.is-active {
background-color: #296DD8 !important;
}

表格样式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 表格头样式
.el-table th {
background-color: #4284DC;
color: #fff;
height: 40px;
padding: 0;
}

// 表格体单行样式
.el-table td {
height: 40px;
padding: 0;
}

// 表格斑马线样式
.el-table--striped .el-table__body tr.el-table__row--striped td {
background: #EAF3FC;
}

// 表格下面有一条线 去掉了
.el-table::before {
height: 0;
}

下拉菜单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
* selecte 框的高度设置,默认是 40px*/
.el-input__inner{
height: 32px;
}
/* 下面设置右侧按钮居中 */
.el-input__suffix {
top: 8px;
}
.el-input__icon {
line-height: inherit;
}
.el-input__suffix-inner {
display: inline-block;
}

// element按钮样式
.el-button {
height: 32px;
padding: 0 10px;
background-color: #296DD8;
border: none;
}

左侧路由记得有个样式配置文件,忘记录了

日期选择器

日期选择器选中格式和显示格式

1
2
3
4
5
6
7
8
<el-date-picker v-model="timevalue" type="daterange" range-separator="至" start-placeholder="开始日期"
end-placeholder="结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
</el-date-picker>

format="yyyy-MM-dd" 展示各式
value-format="yyyy-MM-dd" v-model 打印的数据格式

详情参考官方文档

上传图片

1
2
3
4
5
6
7
8
9
<el-upload class="avatar-uploader" action="#" list-type="picture-card" :auto-upload="false"
:show-file-list="false" :on-change="changeFn">
<div class="imgbox"></div>
</el-upload>

changeFn(file, fileList) {
console.log('file', file);
console.log('fileList', fileList);
},

如果要显示上传的图片的话要加上 list-type=”picture-card”

file 里 的url 就是图片地址

也可以不加

通过接口获取服务器上的地址

table表格

滚动条位置

1
2
3
4
5
6
7
8
9
10
11
12
13
 this.$refs.table.bodyWrapper.scrollTo(0, 0)

https://blog.csdn.net/qq_41646249/article/details/121532349

this.$nextTick(() => {
let scrollHeight = this.$refs.table.bodyWrapper.scrollHeight
this.$refs.table.bodyWrapper.scrollTop = scrollHeight
})

this.$nextTick(() => {
this.$refs.table.bodyWrapper.scrollTo(0, 0)
this.isLoading = false
})

组件插槽

1
2
3
4
5
<template>
<div class="list list-page">
<slot />
</div>
</template>

引用组件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import myTable from '@/componentsNew/table'

export default {
components: {
myTable,
myPagination,
dictPop,
},

<my-table>
<el-table ref="table" v-loading="isLoading" :data="tableData" height="100%" style="width: 100%">
<el-table-column type="selection" width="55" />
<el-table-column prop="dictIds" label="字典编号" align="center" />
<el-table-column prop="dictName" label="字典名称" align="center" />
<el-table-column prop="dictType" label="字典类型" align="center">
<template slot-scope="scope">
<span style="cursor:pointer;color:#02C2B0;" @click="goData(scope.row)">{{ scope.row.dictType }}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center">
<template slot-scope="scope">
<el-tag v-if="scope.row.status == 0">正常</el-tag>
<el-tag v-else type="danger">停用</el-tag>
</template>
</el-table-column>
<el-table-column prop="notes" label="备注" align="center" />
<el-table-column prop="createTime" label="创建时间" width="170" align="center" />
<el-table-column label="操作" align="center">
<template slot-scope="scope">
<span class="smallBtn" @click="createUser('修改', scope.row)">修改</span>
<span class="smallBtn remove" @click="removeUser(scope.row)">删除</span>
</template>
</el-table-column>
</el-table>
</my-table>

有开关的渲染

1
2
3
4
5
6
7
8
9
this.tableData = res.data.records.map(el=>{
// 启用 2禁用
if(el.isDelete == 0){
el.ifswitch = true
}else if(el.isDelete == 2){
el.ifswitch = false
}
return el
})

element-Ui遇到的一些问题点记录
http://www.dwyblog.cn/2024/01/02/element-Ui/
作者
幸福来敲门
发布于
2024年1月2日
许可协议