Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form表单不能进行v-model绑定,进而导致input框验证失败 #3246

Closed
1 task
cxbb666 opened this issue Nov 23, 2020 · 22 comments
Closed
1 task

form表单不能进行v-model绑定,进而导致input框验证失败 #3246

cxbb666 opened this issue Nov 23, 2020 · 22 comments
Labels

Comments

@cxbb666
Copy link

cxbb666 commented Nov 23, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

2.0.0-rc.1

Environment

win10 谷歌85版本 vue3.0.2 vite1.0.0-rc.8

Reproduction link

Edit on CodeSandbox

Steps to reproduce

form表单不能进行v-model绑定,进而导致input框验证失败

What is expected?

form进行v-model绑定

What is actually happening?

form表单不能进行v-model绑定
image
image

@ajuner
Copy link
Member

ajuner commented Nov 23, 2020

<Input value={modelRef.loginEmail} onInput={e=> modelRef.loginEmail = e.target.value}/>
或者
<Input v-model={[modelRef.loginEmail, 'value']}/>

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

image
image
我已经这样写了,为什么还是不行, 我用的是tsx

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

<输入值= {modelRef.loginEmail} onInput = {e => modelRef.loginEmail = e.target.value} />
或者
<输入v-model = {[modelRef.loginEmail,'value']} /> />

图片
图片
我已经这样写了,为什么还是不行,我用的是tsx

@ajuner
Copy link
Member

ajuner commented Nov 23, 2020

<输入值= {modelRef.loginEmail} onInput = {e => modelRef.loginEmail = e.target.value} />
或者
<输入v-model = {[modelRef.loginEmail,'value']} /> />

图片
图片
我已经这样写了,为什么还是不行,我用的是tsx

tsx用useForm的形式试试
https://2x.antdv.com/components/form-cn/#components-form-demo-useform

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

<输入值= {modelRef.loginEmail} onInput = {e => modelRef.loginEmail = e.target.value} />
或者
<输入v-model = {[modelRef.loginEmail,'value']} /> /> />

图片
图片
我已经这样写了,为什么还是不行,我用的是tsx

tsx用useForm的形式尝试
https://2x.antdv.com/components/form-cn/#components-form-demo-useform

这个userForm我之前试过 好像有个地方有点问题 现在没用了

@ajuner
Copy link
Member

ajuner commented Nov 23, 2020

提供一个复现吧~

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

提供一个复现吧~

不能上传视频

@ajuner
Copy link
Member

ajuner commented Nov 23, 2020

用codeSandBox写一个保存路径
image

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

提供一个复现吧~

import { defineComponent, reactive, toRefs, toRaw, ref, onMounted } from 'vue'
import { Form, Input, Button } from 'ant-design-vue'

export default defineComponent({
name: 'register',
setup() {
const ruleForm = ref(null)

const data = reactive({
  labelCol: { span: 4 },
  wrapperCol: { span: 14 }
})

onMounted(() => {
  console.log(ruleForm.value)
})

const onSubmit = (e: Event) => {
}

const modelRef = reactive({
  loginEmail: '',
  password: '',
  confirmPassword: '',
  photoUrl: '',
  code: ''
})

const validatePass = async (rule: any, value: string | number) => {
  if (value === '') {
    return Promise.reject('请输入密码')
  } else {
    if (modelRef.confirmPassword !== '') {
      ruleForm.value.validateField('confirmPassword')
    }
    return Promise.resolve()
  }
}

const validatePass2 = async (rule: any, value: string | number) => {
  if (value === '') {
    return Promise.reject('请输入确认密码')
  } else if (value !== modelRef.password) {
    return Promise.reject('两次密码不一致')
  } else {
    return Promise.resolve()
  }
}

const rulesRef = reactive({
  loginEmail: [
    { required: true, message: '请输入登录邮箱', trigger: 'blur' },
    { message: '请输入正确的邮箱', type: 'email', trigger: 'blur' }
  ],
  password: [
    { validator: validatePass, trigger: 'change' }
  ],
  confirmPassword: [
    { validator: validatePass2, trigger: 'change' }
  ],
  code: [
    { required: true, message: '请输入验证码', trigger: 'blur' }
  ]
})

const tailFormItemLayout = {
  wrapperCol: {
    xs: {
      span: 24,
      offset: 0,
    },
    sm: {
      span: 16,
      offset: 8,
    },
  },
}

return () => {

  return (
    <Form
      ref={ruleForm}
      name="control-ref"
      labelCol={data.labelCol}
      wrapperCol={data.wrapperCol}
      model={modelRef}
      rules={rulesRef}
    >
      <Form.Item
        name="loginEmail"
        label="邮箱"
        hasFeedback
      >
        <Input v-model={[modelRef.loginEmail, 'value']} onChange={value=>console.log(value.target.value,modelRef.loginEmail+'-')} type="email" placeholder='请输入邮箱'/>
      </Form.Item>
      <Form.Item
        name="password"
        label="密码"
        hasFeedback
      >
        <Input.Password value={modelRef.password} onChange={value => modelRef.password = value.target.value} type="password" placeholder='请输入密码'/>
      </Form.Item>
      <Form.Item
        name='confirmPassword'
        label="确认密码"
        hasFeedback
      >
        <Input.Password value={modelRef.confirmPassword} onChange={value => modelRef.confirmPassword = value.target.value} type="password" placeholder='请输入确认密码'/>
      </Form.Item>
      <Form.Item {...tailFormItemLayout}>
        <Button type="primary" htmlType="submit">
          注册
        </Button>
      </Form.Item>
    </Form>
  )
}

}
})
代码都发给你

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

提供一个复现吧~

https://codesandbox.io/embed/vue-antd-template-forked-ovgjb?fontsize=14&hidenavigation=1&theme=dark
看看是不是这样弄的

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

@ajuner
Copy link
Member

ajuner commented Nov 23, 2020

我这跑你的代码也没问题呀
你再检查一下?

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

我这跑你的代码也没问题呀
你再检查一下?

难道是vite的问题?

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

我这跑你的代码也没问题呀
你再检查一下?

你的是vite吗还是webpack

@ajuner
Copy link
Member

ajuner commented Nov 23, 2020

我这跑你的代码也没问题呀
你再检查一下?

你的是vite吗还是webpack

跟这没关系吧

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

另一个人的webpack用这个也可以,我用vite就不行

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

我这跑你的代码也没问题呀
你再检查一下?

你的是vite吗还是webpack

跟这没关系吧

另一个人的webpack用这个也可以,我用vite就不行

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

我这跑你的代码也没问题呀
你再检查一下?

你的是vite吗还是webpack

跟这没关系吧

image
你的这个v-model会被渲染到html上面嘛

@ajuner
Copy link
Member

ajuner commented Nov 23, 2020

不清楚了,等大佬回复吧~

@John60676
Copy link
Member

see vuejs/babel-plugin-jsx#118

@cxbb666
Copy link
Author

cxbb666 commented Nov 23, 2020

see vuejs/jsx-next#118

vite不支持,目前

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants