Browse Source

fix: 修复ScFormTable 数据更新

lanceJiang 1 year ago
parent
commit
1a3badf9cf
1 changed files with 15 additions and 12 deletions
  1. 15 12
      src/components/scFormTable/index.vue

+ 15 - 12
src/components/scFormTable/index.vue

@@ -1,6 +1,6 @@
 <template>
-	<div class="sc-form-table" ref="scFormTableRef">
-		<el-table :data="data" ref="tableRef" border stripe>
+	<div ref="scFormTableRef" class="sc-form-table">
+		<el-table ref="tableRef" :data="data" border stripe>
 			<el-table-column type="index" width="50" fixed="left">
 				<template #header>
 					<el-button v-if="!hideAdd" type="primary" :icon="Plus" size="small" circle @click="rowAdd"></el-button>
@@ -12,9 +12,9 @@
 					</div>
 				</template>
 			</el-table-column>
-			<el-table-column label="" width="50" v-if="dragSort">
+			<el-table-column v-if="dragSort" label="" width="50">
 				<template #default>
-					<div class="move" style="cursor: move"><el-icon-d-caret style="width: 1em; height: 1em" /></div>
+					<div class="move" style="cursor: move"><DCaret style="width: 1em; height: 1em" /></div>
 				</template>
 			</el-table-column>
 			<slot></slot>
@@ -39,7 +39,7 @@ const myProps = defineProps({
 	hideDelete: { type: Boolean, default: false }
 })
 
-const $myEmit = defineEmits(['update:modelValue'])
+const emit = defineEmits(['update:modelValue'])
 
 const data = ref([])
 const tableRef = ref(null)
@@ -84,15 +84,18 @@ const deleteRow = index => {
 	data.value.splice(index, 1)
 }
 
-watch(myProps.modelValue, async (newQuestion, oldQuestion) => {
-	// data.value = myProps.modelValue
-	data.value = newQuestion
-})
+watch(
+	() => myProps.modelValue,
+	(newQuestion, oldQuestion) => {
+		// data.value = myProps.modelValue
+		data.value = newQuestion
+	}
+)
 
 watch(
-	data.value,
-	async (newQuestion, oldQuestion) => {
-		$myEmit('update:modelValue', newQuestion)
+	data,
+	(newQuestion, oldQuestion) => {
+		emit('update:modelValue', newQuestion)
 	},
 	{ deep: true }
 )