当前位置:网站首页>Wangedit encapsulation plug-in preliminary

Wangedit encapsulation plug-in preliminary

2022-06-21 10:40:00 Jimeng network worry free

install

install editor

yarn add @wangeditor/editor
#  perhaps  npm install @wangeditor/editor --save

install Vue3 Components

yarn add @wangeditor/editor-for-[email protected]
#  perhaps  npm install @wangeditor/editor-for-[email protected] --save

In components

If there are other needs , Can be modified by yourself

<template>
    <div style="border: 1px solid #ccc">
      <Toolbar
        style="border-bottom: 1px solid #ccc"
        :editor="editorRef"
        :defaultConfig="toolbarConfig"
        :mode="mode"
      />
      <Editor
        style="height: 500px; overflow-y: hidden;"
        v-model="valueHtml"
        :defaultConfig="editorConfig"
        :mode="mode"
        @onCreated="handleCreated"
      />
    </div>
</template>
<script>
import '@wangeditor/editor/dist/css/style.css' //  introduce  css

import {
     onBeforeUnmount, ref, shallowRef, onMounted ,getCurrentInstance} from 'vue'
import {
     Editor, Toolbar } from '@wangeditor/editor-for-vue'
  const editorRef = shallowRef()

    //  Content  HTML
    const valueHtml = ref('<p>hello</p>')
    const toolbarConfig = {
    }
    const editorConfig = {
     placeholder: ' Please enter the content ...' } 
export default {
    
  components: {
     Editor, Toolbar },
  data() {
    
        return {
    
           editorRef,
            valueHtml,
            mode: 'default', //  or  'simple'
            toolbarConfig,
            editorConfig,
        }
        },
     props:{
    
	        
            //  Binding value  
            htmlval: {
    }, 
         
	},   
  mounted() {
    
       
     this.parseJv()
  },    
  methods:{
     
        parseJv(){
    
            console.log(this.htmlval)
             setTimeout(() => {
    
             
            valueHtml.value = this.htmlval;// '<p> simulation  Ajax  Asynchronous setting content </p>'
        }, 500)
        },
         handleCreated(editor) {
    
            editorRef.value = editor //  Record  editor  example , important !
            } 
  },
  BeforeUnmount(){
    
  const editor = editorRef.value
        if (editor == null) return
        editor.destroy()
  }, 
  setup() {
      
    // //  When components are destroyed , Also destroy the editor in time  
    // const handleCreated = (editor) => {
    
    // editorRef.value = editor //  Record  editor  example , important !
    // } 
    // return { 
    // handleCreated
    // }; 
  }
}
</script>    

quote

<template>
  <WangEditor  :htmlval="htmlStr" />
 
</template>
<script>
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
import WangEditor from './components/form/WangEditor.vue'
export default {
    
  components: {
    WangEditor },
  data() {
    
        return {
     
            htmlStr: '<p>helloasd1</p>', 
        }
    },
}
</script>
原网站

版权声明
本文为[Jimeng network worry free]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211025273770.html