我将在vue中开始从options到compositon的转换。
我有下面的代码块,我试图实现2路绑定。
我使用ant-design-vue库作为滑块输入。并试图将滑块值绑定到输入字段。
<template>
<div>
<a-row>
<a-col :span="12">
<a-slider v-model="inputValue1" :min="1" :max="20" />
</a-col>
<a-col :span="4">
<a-input-number
v-model="inputValue1"
:min="1"
:max="20"
style="marginleft: 16px"
/>
</a-col>
</a-row>
</div>
</template>
<script>
import { ref } from "vue";
export default {
setup() {
let inputValue1 = ref(8);
return { inputValue1 };
},
};
</script>
使用上面的代码,在vue dev工具中检查时,inputValue1的值不会改变。
如何在vue 3组合api中使用双向绑定?
指向沙箱的链接:https://stackblitz.com/edit/vue-pchhub?file=src%2FApp.vue
发布于 2022-03-20 15:36:42
看来您必须使用v-model:value="..."才能工作。
<template>
<div>
<a-row>
<a-col :span="12">
<a-slider v-model:value="inputValue1" :min="1" :max="20" />
</a-col>
<a-col :span="4">
<a-input-number
v-model:value="inputValue1"
:min="1"
:max="20"
style="marginleft: 16px"
/>
</a-col>
</a-row>
</div>
</template>
<script>
import { ref } from "vue";
export default {
setup() {
let inputValue1 = ref(8);
return { inputValue1 };
},
};
</script>https://stackoverflow.com/questions/71547997
复制相似问题