fix(user/index.vue): watchEffect会在DOM挂载或者更新之前就会触发,此属性控制在DOM元素更新后运行

This commit is contained in:
郝先瑞
2022-01-17 23:28:53 +08:00
parent c60186b445
commit 702abe38b8

View File

@@ -15,7 +15,7 @@
style="margin-bottom: 20px" style="margin-bottom: 20px"
/> />
<el-tree <el-tree
ref="treeRef" ref="deptTreeRef"
:data="deptOptions" :data="deptOptions"
:props="{ children: 'children',label: 'label'}" :props="{ children: 'children',label: 'label'}"
:expand-on-click-node="false" :expand-on-click-node="false"
@@ -391,10 +391,10 @@ import {listRoles} from '@/api/system/role'
// 组件依赖 // 组件依赖
import {ElMessage, ElMessageBox, ElTree, ElForm} from 'element-plus' import {ElMessage, ElMessageBox, ElTree, ElForm} from 'element-plus'
import {Search, Plus, Edit, Refresh, Delete,Lock} from '@element-plus/icons' import {Search, Plus, Edit, Refresh, Delete, Lock} from '@element-plus/icons'
import TreeSelect from '@/components/TreeSelect/Index.vue' import TreeSelect from '@/components/TreeSelect/Index.vue'
const treeRef = ref(ElTree) const deptTreeRef = ref(ElTree)
const dataFormRef = ref(ElForm) const dataFormRef = ref(ElForm)
const queryFormRef = ref(ElForm) // 变量名和绑定名ref一致 const queryFormRef = ref(ElForm) // 变量名和绑定名ref一致
@@ -505,14 +505,16 @@ async function loadDeptOptions() {
* 部门筛选 * 部门筛选
**/ **/
watchEffect(() => { watchEffect(() => {
if (state.deptName) { const deptTree = unref(deptTreeRef)
const tree = unref(treeRef) deptTree.filter(state.deptName)
tree.filter(state.deptName) }, {
} flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发此属性控制在DOM元素更新后运行
}) })
function filterDeptNode(value: string, data: any) { function filterDeptNode(value: string, data: any) {
if (!value) return true if (!value) {
return true
}
return data.label.indexOf(value) !== -1 return data.label.indexOf(value) !== -1
} }
@@ -560,7 +562,7 @@ function resetPassword(row: { [key: string]: any }) {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消' cancelButtonText: '取消'
}).then(({value}) => { }).then(({value}) => {
if(!value){ if (!value) {
ElMessage.warning("请输入新密码") ElMessage.warning("请输入新密码")
return false return false
} }
@@ -569,7 +571,7 @@ function resetPassword(row: { [key: string]: any }) {
}).then(() => { }).then(() => {
ElMessage.success('修改成功,新密码是:' + value) ElMessage.success('修改成功,新密码是:' + value)
}) })
}).catch(()=>{ }).catch(() => {
}) })
} }