fix: synchronize vditor content with prop

This commit is contained in:
Tim
2025-07-06 11:01:48 +08:00
parent 5f0eaf10cf
commit d4c2959ee3
2 changed files with 13 additions and 2 deletions

View File

@@ -5,7 +5,7 @@
</template> </template>
<script> <script>
import { ref, onMounted } from 'vue' import { ref, onMounted, watch } from 'vue'
import Vditor from 'vditor' import Vditor from 'vditor'
import 'vditor/dist/index.css' import 'vditor/dist/index.css'
@@ -25,6 +25,15 @@ export default {
setup(props, { emit }) { setup(props, { emit }) {
const vditorInstance = ref(null) const vditorInstance = ref(null)
watch(
() => props.modelValue,
val => {
if (vditorInstance.value && vditorInstance.value.getValue() !== val) {
vditorInstance.value.setValue(val)
}
}
)
onMounted(() => { onMounted(() => {
vditorInstance.value = new Vditor(props.editorId, { vditorInstance.value = new Vditor(props.editorId, {
placeholder: '请输入正文...', placeholder: '请输入正文...',

View File

@@ -61,7 +61,9 @@ export default {
toast.success('草稿已加载') toast.success('草稿已加载')
} }
} catch (e) {} } catch (e) {
console.error(e)
}
} }
onMounted(loadDraft) onMounted(loadDraft)