1、下载Vue-Quill-Editor

  npm install vue-quill-editor --save

2、下载quill(Vue-Quill-Editor需要依赖)

  npm install quill --save

3、使用富文本编辑器:

  vue代码

vue富文本编辑器vue-quill-editor
<template>
    
    <div class="edit_container">
        <p>用户名:<input type="text" v-model="name"></p>
        <!--  新增时输入 -->
        简介
        <quill-editor 
            v-model="content" 
            ref="myQuillEditor" 
            :options="editorOption" 
            @blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
            @change="onEditorChange($event)">
        </quill-editor>
        <!-- 从数据库读取展示 -->
        <p><button @click="post_info()">提交</button></p>
        <div v-html="str" class="ql-editor">
            {{str}}
        </div>
        {{str}}
    </div>

         
     
</template>

<script>
import axios from 'axios'
import { quillEditor } from "vue-quill-editor"; //调用编辑器
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';

export default {
    name:"fuwenben", 
    components: {
        quillEditor
    },
    data() {
        return {
            content: `<p></p><p><br></p><ol><li><strong><em>Or drag/paste an image here.</em></strong></li><li><strong><em>rerew</em></strong></li><li><strong><em>rtrete</em></strong></li><li><strong><em>tytrytr</em></strong></li><li><strong><em>uytu</em></strong></li></ol>`,
            str: '',
            editorOption: {},
            name
        }
    },
    methods: {
        onEditorReady(editor) { // 准备编辑器
 
        },
        onEditorBlur(){}, // 失去焦点事件
        onEditorFocus(){}, // 获得焦点事件
        onEditorChange(){}, // 内容改变事件
        
        post_info(){
            var data_form=new FormData()
            data_form.append("name",this.name)
            data_form.append("content",this.content)
            axios({
                url:"http://127.0.0.1:8000/qiniu/test/",
                method:"post",
                data:data_form

            }).then(res=>{
                console.log(res.data)
                this.str = res.data.data
            })
        }
    },
    computed: {
        editor() {
            return this.$refs.myQuillEditor.quill;
        },
    },
    


}
</script>


   
fuwenben.vue

相关文章: