-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
a-input 组件不受控 #7720
Comments
作者的意思应该是 <a-input :value="msg" /> 如果 msg 为 如有误,请指正 |
那你就拆成以下这种写法再去尝试嘛,所有的事件都控制不了输入框的显示值,。 <template>
<h1>{{ msg }}</h1>
<a-input :value="msg" @update:value="handleChange" />
</template>
<script lang="ts" setup>
import { ref } from "vue";
1;
const msg = ref();
const handleChange = () => {
msg.value = "Hello";
};
</script> |
像你所描述的:’组件完全受控‘,这样当然是最好的。但 vue 官方并未提及受控组件的概念,不像 react 。因此组件受控需要交给组件库去实现。所以我并不清楚提出质疑的那位同志是否了解过这一概念。 我也不说这组件能完全受控,但现在是任何一个事件居然都控制不了输入框的值,直接导致我无法控制字符类型、长度等 |
第一 , msg.value = 'Hello'; 肯定你键盘怎么敲始终都是 Hello 呀,因为只有这里在赋值呀 第二, 如果你想拿到你想输入的值 , 不管是update:value 事件,还是chang事件,还是input事件, 他都有回调参数的,
|
你到底有没有明白别人提这个 issue 的意思,你能不能自己先去理解别人的意思和先尝试再来表达自己的看法。 你第一个评论明显是没理解各个事件的触发时机, <template>
<h1>{{ msg }}</h1>
<!-- 第一种 -->
<a-input :value="msg" @update:value="handleChange" />
<!-- 第二种 -->
<a-input v-model:value="msg" @input="handleChange" />
</template>
<script lang="ts" setup>
import { ref } from "vue";
const msg = ref();
const handleChange = () => {
msg.value = "Hello";
};
</script> |
今天也遇到这个问题了,试了下 elemnt-plus是正常的 |
问题是有,具体原因可以看一下原生input dom的value逻辑,然后看下作者在setValue之后nextTick中回调的逻辑就能看出原因了,作者用的那个$forceUpdate应该是最终比对了属性一样没更新原生input的dom,临时解法是在自己的update:value事件触发时补一个nextTick,回调里通过外层ref取到input的dom节点,如果dom的value与传入给a-input的value不同,就赋值input的dom的value为外面的传入给a-input的value |
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days |
4.2.5版本还是没修改啊 |
<a-input const onFeeInput = (e: any) => { 临时解法 |
Version
undefined
Environment
vue: 3.x ; ant-design-vue: 4.2.3
Reproduction link
a-input 组件不受控
What is expected?
期待 a-input 组件与 a-select 组件一样,都是受控组件
What is actually happening?
no response
The text was updated successfully, but these errors were encountered: