Browse Source

fix(gui-v2): replace by useVModel

pull/2838/head
Wing-Kam Wong 2 years ago
parent
commit
ce5dd5fbb7
  1. 19
      packages/nc-gui-v2/components/api-client/Headers.vue
  2. 19
      packages/nc-gui-v2/components/api-client/Params.vue

19
packages/nc-gui-v2/components/api-client/Headers.vue

@ -6,18 +6,11 @@ interface Props {
modelValue: Record<string, any>[] modelValue: Record<string, any>[]
} }
const { modelValue } = defineProps<Props>() const props = defineProps<Props>()
const emit = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])
const localState = computed({ const vModel = useVModel(props, 'modelValue', emits)
get() {
return modelValue
},
set(newValue: Record<string, any>[]) {
emit('update:modelValue', newValue)
},
})
const headerList = ref([ const headerList = ref([
'A-IM', 'A-IM',
@ -61,9 +54,9 @@ const headerList = ref([
'X-CSRF-Token', 'X-CSRF-Token',
]) ])
const addHeaderRow = () => localState.value.push({}) const addHeaderRow = () => vModel.value.push({})
const deleteHeaderRow = (idx: number) => localState.value.splice(idx, 1) const deleteHeaderRow = (idx: number) => vModel.value.splice(idx, 1)
</script> </script>
<template> <template>
@ -86,7 +79,7 @@ const deleteHeaderRow = (idx: number) => localState.value.splice(idx, 1)
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="(headerRow, idx) in localState" :key="idx"> <tr v-for="(headerRow, idx) in vModel" :key="idx">
<td class="px-2"> <td class="px-2">
<a-form-item> <a-form-item>
<a-checkbox v-model:checked="headerRow.enabled" /> <a-checkbox v-model:checked="headerRow.enabled" />

19
packages/nc-gui-v2/components/api-client/Params.vue

@ -6,22 +6,15 @@ interface Props {
modelValue: Record<string, any>[] modelValue: Record<string, any>[]
} }
const { modelValue } = defineProps<Props>() const props = defineProps<Props>()
const emit = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])
const localState = computed({ const vModel = useVModel(props, 'modelValue', emits)
get() {
return modelValue
},
set(newValue: Record<string, any>[]) {
emit('update:modelValue', newValue)
},
})
const addParamRow = () => localState.value.push({}) const addParamRow = () => vModel.value.push({})
const deleteParamRow = (idx: number) => localState.value.splice(idx, 1) const deleteParamRow = (idx: number) => vModel.value.splice(idx, 1)
</script> </script>
<template> <template>
@ -44,7 +37,7 @@ const deleteParamRow = (idx: number) => localState.value.splice(idx, 1)
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="(paramRow, idx) in localState" :key="idx"> <tr v-for="(paramRow, idx) in vModel" :key="idx">
<td class="px-2"> <td class="px-2">
<a-form-item> <a-form-item>
<a-checkbox v-model:checked="paramRow.enabled" /> <a-checkbox v-model:checked="paramRow.enabled" />

Loading…
Cancel
Save