Open Mr-xzq opened 2 years ago
Actions to access .value
should be written in render function, which makes vue properly collect deps. Try to change your code as below:
export default defineComponent({
setup() {
const date3 = ref(new Date());
return () => <DatePicker v-model={date3.value}></DatePicker>;
},
});
Actions to access
.value
should be written in render function, which makes vue properly collect deps. Try to change your code as below:export default defineComponent({ setup() { const date3 = ref(new Date()); return () => <DatePicker v-model={date3.value}></DatePicker>; }, });
Thanks for your help, your answer resolve my problem.
https://stackblitz.com/edit/vitejs-vite-rmxqpw?file=src/App.vue
@Mr-xzq 我也遇到了,咋解决
@zehuichan
v-model
的本质就是一个语法糖:
一个组件上的 v-model
默认会利用名为 value
的 prop
和名为 input
的事件;
但是像单选框、复选框等类型的输入控件可能会将 value attribute
用于不同的目的;
model
选项可以用来避免这样的冲突;
这是我一个临时的解决方案:https://stackblitz.com/edit/vitejs-vite-hocdde?file=src/components/FormItem.vue
<script lang="jsx">
import { defineComponent, computed, ref } from 'vue';
export default defineComponent({
name: 'FormItem',
inheritAttrs: false,
props: ['value'],
emits: ['input'],
setup(props, { emit }) {
return () => {
return (
<el-input
value={props.value}
vOn:input={(val) => emit('input', val)}
clearable
placeholder="请输入"
/>
);
};
},
});
</script>
@Mr-xzq 感谢解答