lsc 2 年 前
コミット
d324b65240
2 ファイル変更140 行追加0 行削除
  1. 5 0
      src/components/pages/demo.vue
  2. 135 0
      src/components/tools/wangEnditor.vue

+ 5 - 0
src/components/pages/demo.vue

@@ -22,16 +22,21 @@
     <el-button type="primary" size="default" @click="handleSave"
       >保存</el-button
     >
+    <!-- <Editor></Editor> -->
   </div>
 </template>
 
 <script>
 import { regionData, CodeToText } from "element-china-area-data";
 import html2canvas from "html2canvas";
+// import Editor from "../tools/wangEnditor.vue";
 const Data = regionData.filter((ele) => {
   return ele.value == "440000";
 });
 export default {
+  // components: {
+  //   Editor,
+  // },
   data() {
     return {
       options: Data[0].children,

+ 135 - 0
src/components/tools/wangEnditor.vue

@@ -0,0 +1,135 @@
+<template>
+  <div style="border: 1px solid #ccc;">
+      <Toolbar
+          style="border-bottom: 1px solid #ccc"
+          :editor="editor"
+          :defaultConfig="toolbarConfig"
+          :mode="mode"
+      />
+      <Editor
+          style="height: 500px; overflow-y: hidden;"
+          v-model="html"
+          :defaultConfig="editorConfig"
+          :mode="mode"
+          @onCreated="onCreated"
+      />
+  </div>
+</template>
+  
+<script>
+import Vue from 'vue'
+import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
+import '@wangeditor/editor/dist/css/style.css'
+
+export default Vue.extend({
+    components: { Editor, Toolbar },
+    data() {
+        return {
+            editor: null,
+            html: '<p>hello</p>',
+            toolbarConfig: { },
+            editorConfig: { placeholder: '请输入内容...' },
+            mode: 'default', // or 'simple'
+        }
+    },
+    methods: {
+        onCreated(editor) {
+            this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
+        },
+    },
+    mounted() {
+        // 模拟 ajax 请求,异步渲染编辑器
+        setTimeout(() => {
+            this.html = '<p>模拟 Ajax 异步设置内容 HTML</p>'
+        }, 1500)
+    },
+    beforeDestroy() {
+        const editor = this.editor
+        if (editor == null) return
+        editor.destroy() // 组件销毁时,及时销毁编辑器
+    }
+})
+</script>  
+  
+<style lang="css" scoped>
+.editor {
+  width: 100%;
+  margin: 10px auto;
+  position: relative;
+  z-index: 0;
+}
+.toolbar {
+  border: 1px solid #ccc;
+}
+.text {
+  border: 1px solid #ccc;
+  height: 230px;
+  overflow: auto;
+}
+
+/* table 样式 */
+.editor>>>table {
+  border-top: 1px solid #ccc;
+  border-left: 1px solid #ccc;
+}
+
+.editor>>>table td,
+.editor>>>table th {
+  border-bottom: 1px solid #ccc;
+  border-right: 1px solid #ccc;
+  padding: 20px 5px;
+}
+
+.editor>>>table th {
+  border-bottom: 2px solid #ccc;
+  text-align: center;
+}
+
+/* blockquote 样式 */
+.editor>>>blockquote {
+  display: block;
+  border-left: 8px solid #d0e5f2;
+  padding: 5px 10px;
+  margin: 10px 0;
+  line-height: 1.4;
+  font-size: 100%;
+  background-color: #f1f1f1;
+}
+
+/* code 样式 */
+.editor>>>code {
+  display: inline-block;
+  *display: inline;
+  *zoom: 1;
+  background-color: #f1f1f1;
+  border-radius: 3px;
+  padding: 3px 5px;
+  margin: 0 3px;
+}
+
+.editor>>>pre code {
+  display: block;
+}
+
+/* ul ol 样式 */
+.editor>>>ul,
+ol {
+  margin: 10px 0 10px 20px;
+}
+
+.editor>>>.w-e-text p, 
+.editor>>>.w-e-text h1, 
+.editor>>>.w-e-text h2, 
+.editor>>>.w-e-text h3, 
+.editor>>>.w-e-text h4, 
+.editor>>>.w-e-text h5, 
+.editor>>>.w-e-text table, 
+.editor>>>.w-e-text pre{
+  line-height: 1.15;
+  margin: 5px 0 !important;
+}
+.editor >>> .w-e-text-container .placeholder{
+  font-size: 14px;
+  color: #757575;
+}
+</style>