index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <div class="cip-password-confirm">
  3. <el-form-item :prop="fieldKey" :rules="rules">
  4. <cip-password :modelValue="modelValue" @update:modelValue="emitInput"></cip-password>
  5. </el-form-item>
  6. </div>
  7. </template>
  8. <script>
  9. import { ElFormItem } from 'element-plus'
  10. import { formInputProps } from '../../form-input-props'
  11. import CipPassword from '../../basic/password'
  12. export default {
  13. name: 'password-confirm',
  14. components: {
  15. ElFormItem, CipPassword
  16. },
  17. props: formInputProps,
  18. emits: ['update:modelValue'],
  19. setup (props, { emit }) {
  20. const rules = [
  21. {
  22. validator: (rule, value, callback) => {
  23. if (!value) {
  24. return callback(new Error('请再次输入密码'))
  25. }
  26. if (value !== props.otherValue) { // 通过otherkey把密码字段的值传入进行对比
  27. callback(new Error('两次密码输入不一致'))
  28. } else {
  29. callback()
  30. }
  31. },
  32. trigger: 'blur'
  33. }
  34. ]
  35. const emitInput = (val) => {
  36. emit('update:modelValue', val)
  37. }
  38. return {
  39. rules,
  40. emitInput
  41. }
  42. }
  43. }
  44. </script>
  45. <style lang="less">
  46. .cip-password-confirm{
  47. width: 100%;
  48. }
  49. </style>