• vue富文本编辑器vue-quill-editor


    1、下载Vue-Quill-Editor

      npm install vue-quill-editor --save

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

      npm install quill --save

    3、使用富文本编辑器:

      vue代码

    <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

      django代码

    from django.db import models
    
    # Create your models here.
    
    class Test(models.Model):
        name = models.CharField(max_length=32)
        content = models.TextField()
    model.py
    from rest_framework.views import APIView
    from rest_framework.response import Response
    from .models import Test
    
    class Test1(APIView):
        def post(self,request):
            print(request.data)
            info = Test.objects.create(name=request.data["name"],content=request.data["content"])
            last = Test.objects.filter().last()
            return Response({"code":200,"data":last.content})
    views.py

    4、前端显示富文本编辑的内容

    //显示适合HTML的内容
    <div v-html="str" class="ql-editor">
                {{str}}
    </div>
    
    //显示原文本
    {{str}}
    View Code

     

  • 相关阅读:
    微信公众号开发之用户地理位置坐标转百度坐标
    PHP变量入门教程(1)基础
    【很变态】PHP类实例化对象竟然可以访问类的“静态(static)方法”!!!
    【转】记录PHP、MySQL在高并发场景下产生的一次事故
    PHP返回32位与16位的md5加密值
    PhpStorm 8.x/9.x 快捷键设置/个性化设置,如何多项目共存?如何更换主题?
    Linux设置Memcached开机启动
    【荐】MongoDB基本命令大全
    【荐】PHP操作MongoDB GridFS 存储文件,如图片文件
    Shell入门教程:流程控制(7)break和continue
  • 原文地址:https://www.cnblogs.com/ppzhang/p/12390452.html
Copyright © 2020-2023  润新知