fix: can not refresh value display after edit

This commit is contained in:
Lykin 2024-04-19 17:21:20 +08:00
parent 971c89a5cf
commit a682aabb0b
2 changed files with 18 additions and 0 deletions

View File

@ -23,6 +23,10 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: false, default: false,
}, },
resetKey: {
type: String,
default: '',
},
offsetKey: { offsetKey: {
type: String, type: String,
default: '', default: '',
@ -144,6 +148,17 @@ watch(
}, },
) )
watch(
() => props.resetKey,
async () => {
if (editorNode != null) {
editorNode.setValue(props.content)
await nextTick(() => emit('reset', props.content))
updateScroll()
}
},
)
watch( watch(
() => props.offsetKey, () => props.offsetKey,
() => { () => {

View File

@ -71,6 +71,7 @@ const viewAs = reactive({
}) })
const editingContent = ref('') const editingContent = ref('')
const resetKey = ref('')
const enableSave = computed(() => { const enableSave = computed(() => {
return editingContent.value !== viewAs.value && !props.loading return editingContent.value !== viewAs.value && !props.loading
@ -110,6 +111,7 @@ const onFormatChanged = async (decode = '', format = '') => {
viewAs.decode = decode || retDecode viewAs.decode = decode || retDecode
viewAs.format = format || retFormat viewAs.format = format || retFormat
browserStore.setSelectedFormat(props.name, props.keyPath, props.db, viewAs.format, viewAs.decode) browserStore.setSelectedFormat(props.name, props.keyPath, props.db, viewAs.format, viewAs.decode)
resetKey.value = Date.now().toString()
} finally { } finally {
converting.value = false converting.value = false
} }
@ -207,6 +209,7 @@ defineExpose({
:language="viewLanguage" :language="viewLanguage"
:loading="props.loading" :loading="props.loading"
:offset-key="props.keyPath" :offset-key="props.keyPath"
:reset-key="resetKey"
class="flex-item-expand" class="flex-item-expand"
keep-offset keep-offset
style="height: 100%" style="height: 100%"