1
2
3
4
5
6
7
8
9
10
11
12
13
| //useVmodel2.js
| import { toRef, watch, getCurrentInstance } from 'vue';
| export function useVmodel(props, key = 'modelValue', emit) {
| const vm = getCurrentInstance();
| const _emit = emit || vm?.emit;
| const event = `update:${key}`;
| const proxy = toRef(props, key); //ref(props[key]);
| watch(
| () => proxy.value,
| (v) => _emit(event, v),
| );
| return proxy;
| }
|
|