vue中使用vue-quill-editor及上传图片到自己服务器
第一步,下载依赖
cnpm install vue-quill-editor --save
第二步,再main.js里引入组件(我这里是全局注册)
// 富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css' Vue.use(VueQuillEditor)
第三步,如果要上传图片到自己服务器的话如下
cnpm install vue-quill-editor-upload --save
接下来再组件中使用
//js布冯
import {quillRedefine} from 'vue-quill-editor-upload'
data(){
return{
editorOption: {
modules:{
toolbar:[
['image'],
[{ 'color': [] }, { 'background': [] }]
]
}
},
}
},
components: {quillRedefine},
computed: {
editor() {
return this.$refs.myQuillEditor.quill;
}
},
methods: {
onEditorReady(editor) { // 准备编辑器
},
onEditorBlur(){}, // 失去焦点事件
onEditorFocus(){}, // 获得焦点事件
onEditorChange(event){
console.log(event.html)
this.htmls = event.html
}, // 内容改变事件
},
created: function() {
let that = this;
that.upLoadUrl=upLoadUrl+'/?width=300';
that.editorOption = quillRedefine(
{
// 图片上传的设置
uploadConfig: {
action: that.upLoadUrl, // 必填参数 图片上传地址
// 必选参数 res是一个函数,函数接收的response为上传成功时服务器返回的数据
// 你必须把返回的数据中所包含的图片地址 return 回去
res: (respnse) => {
console.log(respnse)
var path = respnse.path//这里return你的图片地址即可
return path
},
name: 'img' // 图片上传参数名
},
toolOptions: [
[{'color': []}, {'background': []}],
[ 'image']
]
}
)
}
temple里的代码是
<quill-editor
v-model="dataInfo.description"
ref="myQuillEditor"
:options="editorOption"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@change="onEditorChange($event)">
</quill-editor>
这样就可以正常操作了,注:上方的 upLoadUrl 需要根据你们的上传地址修改
vue中使用vue-quill-editor及上传图片到自己服务器的更多相关文章
- Vue中通过Vue.extend动态创建实例
Vue中通过Vue.extend动态创建实例 在Vue中,如果我们想要动态地来控制一个组件的显示和隐藏,比如通过点击按钮显示一个对话框或者弹出一条信息.我们通常会提前写好这个组件,然后通过v-if = ...
- Vue 中的Vue Router一级路由,二级路由,三级路由以及跳转
今天编写了一下Vue中的路由 先用命令行新建一个空的项目,并且我知道要用路由,就下载了路由的相关依赖 vue init webpack demo5 完毕之后进入所在的项目 cd demo5 之后用vs ...
- vue中 裁剪,预览,上传图片 的插件
参考地址: https://github.com/dai-siki/vue-image-crop-upload
- Vue中使用Vue.component定义两个全局组件,用单标签应用组件时,只显示一个组件的问题和 $emit的使用。
解决方法: 定义了两个 Vue.component 在 el 中使用的时候要用 双标签, 用单表标签的时候,只会显示第个 组件间 这样写只显示 welcome-button 组件 <welcom ...
- vue中使用定时器时this指向问题
在写一个很小的demo时,用的普通函数写法,没有用es6箭头函数,发现this变化了,后来查找到了问题所在: 箭头函数中的this指向是固定不变(定义函数时的指向),在vue中指向vue 普通函数中的 ...
- [Vue 牛刀小试]:第十二章 - 使用 Vue Router 实现 Vue 中的前端路由控制
一.前言 前端路由是什么?如果你之前从事的是后端的工作,或者虽然有接触前端,但是并没有使用到单页面应用的话,这个概念对你来说还是会很陌生的.那么,为什么会在单页面应用中存在这么一个概念,以及,前端路由 ...
- 聊聊 Vue 中 provide/inject 的应用
众所周知,在组件式开发中,最大的痛点就在于组件之间的通信.在 Vue 中,Vue 提供了各种各样的组件通信方式,从基础的 props/$emit 到用于兄弟组件通信的 EventBus,再到用于全局数 ...
- vue中使用定时器时this指向
箭头函数中的this指向是固定不变(定义函数时的指向),在vue中指向vue; 普通函数中的this指向是变化的(使用函数时的指向),谁调用的指向谁. 箭头函数: let timerOne = s ...
- 在django中部署vue项目,不单独抽离dist文件
1,在django项目下(app所在目录),新建vue项目,使用脚手架构建vue项目,vue create (项目名) 2,构建好以后,配置django: (1),配置settings: · 修改te ...
随机推荐
- Mybatis Annotation使用小结
Mybatis Annotation使用小结 之前一直有看过mybatis的注解使用方式,但没有去看过它的原理.今天看springboot-mybatis-annotation使用的时候,debug了 ...
- 51Nod1222 最小公倍数计数 数论 Min_25 筛
原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1222.html 题意 给定 $a,b$, 求 $$\sum_{n=a}^b \sum_{i=1}^n ...
- zabbix环境安装搭建
一.Zabbix简介 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.zabbix由zabbix server与可选组件zabbix agent两部分组成. ...
- django——web框架简介
1.web应用 Web应用程序是一种可以通过Web访问的应用程序,程序的最大好处是用户很容易访问应用程序,用户只需要有浏览器即可,不需要再安装其他软件. 应用程序有两种模式C/S.B/S.C/S是客户 ...
- [深度学习入门]batch_size的意义
转自->https://www.zhihu.com/question/32673260
- Chapter 2 Basic Elements of JAVA
elaborate:详细说明 Data TypesJava categorizes data into different types, and only certain operationscan ...
- 运行make_datafiles的过程
1. 第一个bug 运行 echo "Please tokenize this text." | java edu.stanford.nlp.process.PTBTokenize ...
- JavaScript 特效之四大家族(offset/scroll/client/event)
三大系列:offset.scroll.client 事件对象:event(事件被触动时,鼠标和键盘的状态)(通过属性控制) 三大系列都是以DOM元素节点的属性形式存在的. 类比访问关系,也是以 ...
- React 简介及其基本使用
相关概念: 插件: 别人写好的第三方库 xxx 插件: jQuery 插件 / react 插件 全家桶: 核心库 + 相关插件 构建项目: 对项目源码 进行 编译.合并.压缩......处理,生 ...
- [LeetCode] To Lower Case 转为小写
Implement function ToLowerCase() that has a string parameter str, and returns the same string in low ...