This commit is contained in:
lzp
2026-03-04 15:25:56 +08:00
parent c95ddf9c54
commit eb67982228
2 changed files with 9 additions and 2 deletions

View File

@@ -22,14 +22,14 @@
</template>
<script setup lang="ts">
import { reactive, ref, nextTick, useAttrs, inject, watch } from 'vue'
import { reactive, ref, onMounted } from 'vue'
const props = defineProps({
data: {
type: Object,
default: () => ({})
}
})
const emit = defineEmits(['delete-node', 'copy-node'])
const emit = defineEmits(['update-data'])
const data = reactive({
text: props.data?.text || '双击编辑文本'
})
@@ -39,6 +39,7 @@
const onInput = () => {
const text = inputRef.value.innerText
data.text = text
emit('update-data', data)
}
const onBlur = () => {
edit.value = false
@@ -56,6 +57,10 @@
const onMouseDown = (e: MouseEvent) => {
if (edit.value) e.stopPropagation()
}
onMounted(() => {
inputRef.value.innerHTML = data.text
emit('update-data', data)
})
defineExpose({ data })
</script>
@@ -69,6 +74,7 @@
> .input {
outline: none;
min-width: 1px;
font-size: 16px;
}
}
</style>

View File

@@ -32,6 +32,7 @@
v-bind="node.data"
@delete-node="deleteNode(node.id)"
@copy-node="copyNode(node.id)"
@update-data="(v) => (node.data.data = v)"
/>
</node>
</template>