<template>
    <div ref="cesEditor"></div>
</template>

<script>
    export default {
        name: 'u-e',
        data() {
            return {
                editor: null
            };
        },
        props: {
            value: '',
            config: {},
            id: ''
        },
        watch: {
            // 如果 `question` 发生改变，这个函数就会运行
            value: function (newQuestion, oldQuestion) {
                this.editor.setContent(newQuestion);
            }
        },
        mounted() {
            let script = document.createElement('script');
            script.id = this.id;
            this.$refs.cesEditor.append(script);
            this.editor = window.UE.getEditor(this.id, this.config);
            this.editor.addListener('ready',  () => {
                this.editor.setContent(this.value);
            });
        },
        methods: {
            getUEContent() {
                return this.editor.getContent();
            }
        },
        destroyed() {
            this.editor.destroy();
        }
    };
</script>

<style scoped>

</style>
