1.前端代码

前端HTML

<script src="https://cdn.bootcss.com/wangEditor/10.0.13/wangEditor.js"></script>
<link href="https://cdn.bootcss.com/wangEditor/10.0.13/wangEditor.css" rel="stylesheet"> <div id="app" style="margin-top: 60px;">
<el-row>
<el-col :span="16" :offset="4">
<div id="editor">
<p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
</div>
</el-col>
<el-col :span="4" :offset="16" style="margin-top: 20px;">
<el-button type="primary" @click="handleAdd" id="btn1">添加</el-button>
</el-col>
</el-row>
</div>

前端js

<script type="text/javascript">
new Vue({
el: '#app',
data: {
editor: null
},
mounted() {
this.init()
},
methods: {
init() {
const E = window.wangEditor;
this.editor = new E(document.getElementById('editor'));
this.editor.customConfig.uploadImgServer = '/upload_img/';
this.editor.customConfig.showLinkImg = false;
this.editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
this.editor.customConfig.uploadImgMaxLength = 5;
this.editor.customConfig.withCredentials = true;
this.editor.create();
},
handleAdd() {
console.log(this.editor.txt.html());
console.log(this.editor.txt.text());
axios.post(site_url + "create_blog/", {"content": this.editor.txt.html()}).then(res => {
if (res.data.result) {
this.$message.success('添加内容成功');
} else {
this.$message.error('添加内容失败');
}
}, 'json');
}
}
})
</script>

2.后端代码(python + Django)

django路由

from django.conf.urls import patterns

from home_application import host_view

urlpatterns = patterns(
'home_application.views',
(r'^$', 'home'),
(r'^api/test/$', "test"),
(r'^upload_img/$', host_view.upload_img),
(r'^media/(?P<name>\d+).(?P<postfix>\w+)', host_view.get_media),
...
)

django视图

import os
import time from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse, HttpResponse
from django.utils.encoding import escape_uri_path def check_upload_wrapper(func):
def inner(*args, **kwargs):
if not os.path.exists("media/"):
os.makedirs("media/")
return func(*args, **kwargs)
return inner def create_blog(request):
data = json.loads(request.body)
content = data.get("content")
print(content)
return JsonResponse({"result": True}) def get_media(request, name, postfix):
file_name = name + "." + postfix
file_path = os.path.join("media", file_name)
file = open(file_path, 'rb')
response = HttpResponse(file)
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = "attachment;filename*=utf-8''{}".format(escape_uri_path(file_name))
return response @csrf_exempt
@check_upload_wrapper
def upload_img(request):
file_list = [] for k, v in request.FILES.items():
t = time.strftime('%Y%m%d%H%M%S')
now_file_name = t + '.' + k.split('.')[-1]
file_path = os.path.join('media', now_file_name) with open(file_path, "ab") as f:
f.write(v.read())
file_list.append("/" + file_path) return JsonResponse({"errno": 0, "data": file_list})

Vue.js中使用wangEditor富文本编辑器的更多相关文章

  1. 在 Vue 项目中引入 tinymce 富文本编辑器

    项目中原本使用的富文本编辑器是 wangEditor,这是一个很轻量.简洁编辑器 但是公司的业务升级,想要一个功能更全面的编辑器,我找了好久,目前常见的编辑器有这些: UEditor:百度前端的开源项 ...

  2. vue项目中使用百度富文本编辑器ueditor

    第一步,安装依赖,并且把ueditor整个文件夹放入public里边 第二步,在你需要编辑的地方引入,或者main.js中全局引入 XX.vue文件中写入下面代码,创建编辑器. <vue-ued ...

  3. 更加简洁易用——wangEditor富文本编辑器新版本发布

    1. 前言 wangEditor富文本编辑器(www.wangEditor.com)从去年11月份发布,至今已经有将近10各月了.它就像一个襁褓中的小婴儿,在我的努力以及众多使用者的支持下不断摸索.成 ...

  4. JS编写自己的富文本编辑器

    富文本编辑器,网上有很多功能齐全种类丰富的如百度的Ueditor,简单适用型的如WangEditor等等.在经过一番挑选后,我发现都不适用现在的项目,然后决定自己造轮子玩玩.富文本编辑器中主要涉及到J ...

  5. 「newbee-mall新蜂商城开源啦」 页面优化,最新版 wangEditor 富文本编辑器整合案例

    大家比较关心的新蜂商城 Vue3 版本目前已经开发了大部分内容,相信很快就能够开源出来让大家尝鲜了,先让大家看看当前的开发进度: 开源仓库地址为 https://github.com/newbee-l ...

  6. vue2.0项目中使用Ueditor富文本编辑器示例

    最近在vue项目中需要使用富文本编辑器,于是将Ueditor集成进来,作为公共组件. 在线预览:https://suweiteng.github.io/vue2-management-platform ...

  7. Vue 中使用UEditor富文本编辑器-亲测可用-vue-ueditor-wrap

    其中UEditor中也存在不少错误,再引用过程中. 但是UEditor相对还是比较好用的一个富文本编辑器. vue-ueditor-wrap说明 Vue + UEditor + v-model 双向绑 ...

  8. Vue系列:wangEditor富文本编辑器简单例子

    考虑到该富文本编辑器可能会在后续项目中继续使用,因此单独将其做成一个组件,把wangeditor作为组件的形式使用. 以下是参考代码 子组件部分: 父组件引用子组件: 以上就是 wangEditor ...

  9. vue中引入Tinymce富文本编辑器

    最近想在项目上引入一个富文本编辑器,之前引入过summernote,感觉并不太适合vue使用, 然后在网上查了查,vue中使用Tinymce比较适合, 首先,我们在vue项目的components文件 ...

随机推荐

  1. React - 组件:函数组件

    目录: . 组件名字首字母一定是大写的 . 返回一个jsx . jsx依赖React,所以组件内部需要引入React . 组件传参 a. 传递. <Component list={ arrDat ...

  2. Salesforce 开发整理(三)权限共享

    Salesforce提供对象的访问权限可以通过 安全性控制 → 共享设置,可以查看每个对象在系统内部默认的访问权限 共用读写:对象的记录任何用户都可以进行读写操作 公用只读:对象的记录任何用户都可以查 ...

  3. 最新版IntelliJ IDEA2019破解方法、补丁、注册码(激活码),永久激活

    最新版IntelliJ IDEA2019破解方法.补丁.注册码(激活码),永久激活 目录 1.打赏记录 2.适用版本(适用于Windows及MacOS系统) 3.下载补丁 4.JetbrainsIde ...

  4. Redis哨兵、复制、集群的设计原理与区别

    一 前言 谈到Redis服务器的高可用,如何保证备份的机器是原始服务器的完整备份呢?这时候就需要哨兵和复制. 哨兵(Sentinel):可以管理多个Redis服务器,它提供了监控,提醒以及自动的故障转 ...

  5. Jquery源码解析及案例分析

    本人刚学先上链接(别人写的挺好的)后期同步补上

  6. java基础 super和this

    /** * super关键字的用法有三种: * 1.在子类的成员方法中,访问父类的成员变量 * 2.在子类的成员方法中,访问父类的成员方法 * 3.在子类的构造方法中,访问父类的构造方法 * * th ...

  7. MongoDB netcore

    mongodb.driver mongodb.driver.core url:  http://dl.mongodb.org/dl/win32/x86_64 ********************* ...

  8. T-SQL 批量更新字段

    ;WITH IdPhone AS ( SELECT * FROM(VALUES ('), ('), ('), ('), ('), ('), ('), ('), ('), (') ) AS v(Id, ...

  9. springboot使用 @Transactional 注解配置事务管理

    介绍 springboot对数据库事务的使用非常的方便,只需要在方法上添加@Transactional注解即可.Spring 为事务管理提供了丰富的功能支持.Spring 事务管理分为编程式和声明式的 ...

  10. windows如果在IE中用超链接打开谷歌页面

    Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\openChrome] @="URL:openChrome Protocol& ...