Skip to content

Commit

Permalink
feature: 添加富文本编辑器
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Jan 22, 2022
1 parent 0cc6968 commit bfae205
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"echarts": "^5.2.2",
"element-plus": "^1.3.0-beta.5",
"es6-promise": "^4.2.8",
"i18next": "^21.6.7",
"intro.js": "^4.3.0",
"lodash-es": "^4.17.21",
"mockjs": "^1.1.0",
Expand Down
40 changes: 37 additions & 3 deletions src/views/editor/richText/index.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
<template>
<div class="page-container"></div>
<div class="page-container">
<div ref="editorELRef"></div>
<div class="innerHTML" :innerHTML="html"></div>
</div>
</template>
<script lang="ts" setup>
// import wangeditor from 'wangeditor';
import { onMounted, ref, unref } from 'vue';
import wangeDitor from 'wangeditor';
import i18next from 'i18next';
import { useI18n } from '@/hooks/web/useI18n';
const editorELRef = ref<HTMLElement>({} as HTMLElement);
const editor = ref<wangeDitor>({} as wangeDitor);
const html = ref<string>('');
const { locale } = useI18n();
function init() {
editor.value = new wangeDitor(unref(editorELRef));
editor.value.config.lang = locale.value === 'zh-ch' ? 'zh-ch' : 'en';
editor.value.i18next = i18next;
editor.value.config.height = 500;
Object.assign(editor.value.config, {
onchange() {
html.value = editor.value.txt.html() as string;
},
});
editor.value.create();
}
onMounted(() => {
init();
});
</script>

<style lang="scss"></style>
<style lang="scss">
.innerHTML {
margin-top: 20px;
min-height: 50px;
border: 1px solid #e3e3e3;
}
</style>

0 comments on commit bfae205

Please sign in to comment.