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. 使用vue搭建应用六实现登录页

    1.js_cookie js-cookie插件是一个JS操作cookie的插件 安装 yarn add js-cookie 使用 写入 Cookies.set('name', 'value'); 读取 ...

  2. 关于Keras 版本的安装与修改

    神经协同过滤(Neural Collaborative Filtering)神作的源码的实验设置要求是: 然而,我们使用控制台 (命令:)或者是PyCharm直接安装的版本均是 最新版本(即 2.0版 ...

  3. CUDA C编程入门

    最近想用cuda来加速三维重建的算法,就先入门了一下cuda. CUDA C 编程 cuda c时对c/c++进行拓展后形成的变种,兼容c/c++语法,文件类型为'.cu',编译器为nvcc.cuda ...

  4. thinkphp验证码不现实多半是bom惹的祸

    thinkphp 验证码不现实多半是bom惹的祸,下面是驱除bom的代码: 链接:https://pan.baidu.com/s/1v5gm7n0L7TGyejCmQrMh2g 提取码:x2p5 免费 ...

  5. VisualSVN 新版本终于支持一个解决方案下多workcopy了,并解决了上个版本一个重要BUG

    Multiple working copies within a single solution VisualSVN 7.0 and older require the solution file a ...

  6. 一、docker 入坑(win10和Ubuntu 安装)

    前言 终究还是绕不过去了,要学的知识真的是太多了,好在我们还有时间,docker 之前只闻其声,不曾真正的接触过,现在docker 越来越火,很多公司也都开始使用了.所以对于我们程序员而言,又得修炼一 ...

  7. 系统压测结果对比:tomcat/thinkphp/swoole/php-fpm/apache

    [测试所用服务器8核,16G内存]压测接口:很简单,从一张表里根据主键随机查询出一条数据[数据库服务器和WEB服务器分开的].表数据量大概:910000+条. 这个测试结果很有趣:tp5.0和3.2性 ...

  8. Linux学习笔记之rpm包管理功能全解

    0x00 软件包管理器 所有的软件都是由文件格式的程序代码(即源代码),经过编译成为一个可执行二进制文件:对于一个软件来说,其包含二进制程序.库文件.配置文件以及帮助文件.在应用中,每次要安装程序时通 ...

  9. jQuery中cookie的简单操作

    jQuery 可以通过 jquery.cookie.js 插件来操作 Cookie. 用NuGet安装:PM>Install-Package js-cookie -Version 官网:http ...

  10. (原创)MODBUS-TCP协议分析