mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-04 17:08:47 +08:00
fix: synchronize vditor content with prop
This commit is contained in:
@@ -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: '请输入正文...',
|
||||||
|
|||||||
@@ -61,7 +61,9 @@ export default {
|
|||||||
|
|
||||||
toast.success('草稿已加载')
|
toast.success('草稿已加载')
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(loadDraft)
|
onMounted(loadDraft)
|
||||||
|
|||||||
Reference in New Issue
Block a user