<el-form-item v-if="!['system','safe','audit','report','ldap'].includes(editForm.userCode)" prop="expirationDate" :label="'用户有效期(单位:天)'"> <el-input v-model="editForm.expirationDate" clearable></el-input> </el-form-item> 如果我想让当前登录用户在编辑自己的用户信息的时候只能查看这个不能修改这个 该怎么做
时间: 2024-02-01 18:13:38 浏览: 17
你可以在判断当前登录用户是否为编辑的用户本人,如果是,则将这个表单项设置为只读,不允许修改。你可以在该表单项的el-input上添加一个属性`:readonly="isCurrentUser(editForm.userCode)"`,其中isCurrentUser是一个自定义函数,判断当前登录用户是否为编辑的用户本人。实现代码如下:
```
<el-form-item v-if="!['system','safe','audit','report','ldap'].includes(editForm.userCode)" prop="expirationDate" :label="'用户有效期(单位:天)'">
<el-input v-model="editForm.expirationDate" clearable :readonly="isCurrentUser(editForm.userCode)"></el-input>
</el-form-item>
```
然后在Vue组件中定义isCurrentUser函数:
```
methods: {
isCurrentUser(userCode) {
return this.$store.state.user.userCode !== userCode
}
}
```
其中,$store.state.user.userCode为当前登录用户的用户编码,如果与编辑的用户的用户编码一致,则返回false,否则返回true,表示当前登录用户不是编辑的用户本人。这样,当当前登录用户编辑自己的用户信息时,就只能查看不能修改这个表单项了。