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. 应用JWT进行用户认证及Token的刷新

    本文将通过实际的例子来演示如何在ASP.NET Core中应用JWT进行用户认证以及Token的刷新方案(ASP.NET Core 系列目录) 一.什么是JWT? JWT(json web token ...

  2. Orm 配置说明

    一.在线技术文档: http://files.cnblogs.com/files/humble/d.pdf   二.使用的大致流程   1.首先下载代码生成器,可以一键生成项目Model层;(其中含有 ...

  3. [记录]mscorlib recursive resource lookup bug解决方法

    [Content]Expression: [mscorlib recursive resource lookup bug]Description: Infinite recursion during ...

  4. HTML5微信jssdk录音播放语音的方法

    HTML5微信jssdk录音播放语音的方法需要注意的2个问题1 就是一定要判断1秒内 录音都不算 ps:太短不能录音 2 录音超过1分钟 会发现正在录音突然消失 所以要写wx.onVoiceRecor ...

  5. Linux之三剑客

    LINUX之三剑客 本篇主要介绍linux下常用的增删改查工具: grep sed awk grep是linux下一个强大的搜索工具,几乎操作linux的用户每天都会或多或少的用到grep命令,单一个 ...

  6. VisualStudio更改项目文件夹名称

    新建了一个空的解决方案(SolutionTest.sln),在文件夹Api中新建了一个webapi项目,物理位置为解决方案根目录下的叫Api文件夹里, 现在想把文件夹名由Api改为MyApi,需要做以 ...

  7. [转帖]ORACLE 12C连接时报ORA28040和ORA01017的错误

    ORACLE 12C连接时报ORA28040和ORA01017的错误 http://blog.itpub.net/12679300/viewspace-2150667/ 我一直在的处理方式是让更新or ...

  8. 【题解】Luogu P2447 [SDOI2010]外星千足虫

    原题传送门 根据题意,题目给的每个操作就相当于异或上选中的那几只虫子的足数(mod 2)等于0/1 这是一个异或方程组,珂以用高斯消元解出每个虫子的足数(mod 2).所需最小次数或判断有多解 但是看 ...

  9. [CF852E]Casinos and travel(2019-11-15考试)

    题目大意 有一棵\(n\)个点的树,令\(f(u)\)表示给树黑白染色,满足以\(u\)为根的树中,每个叶子节点到根的路径上黑点数量为偶数的染色方案数,求\(\sum\limits_{u=1}^n f ...

  10. Java学习:数据类型转换注意事项

    数据类型的转换 当数据类型不一样时,将会发生数据类型转换. 自动类型转换(隐式) 1.特点 :代码不需要进行特殊处理,自动完成. 2.规则 :数据范围从小到大. //左边是long类型,右边是默认的i ...