网站首页 > 技术文章 正文
今天给小伙伴们分享一款超好用的Vue富文本编辑器Vue2Editor。
vue2-editor 一个底层基于 Quill.js 构建的vue2.x版本图文编辑器组件,star高达2K+。简单易上手的API及丰富的自定义参数配置。
特性
- 快速且轻量级、易于上手
- 基于vue.js & Quill.js
- 标准化HTML
- 支持自定义配置
安装
$ npm i vue2-editor -S
引入插件
// 在main.js全局引入
import Vue from "vue";
import Vue2Editor from "vue2-editor";
Vue.use(Vue2Editor);
// 在.vue页面局部引入
<script>
import { VueEditor } from "vue2-editor";
export default {
components: {
VueEditor
},
};
</script>
基础版
<template>
<vue-editor v-model="content" />
</template>
<script>
import { VueEditor } from "vue2-editor";
export default {
components: { VueEditor },
data: () => ({
content: "<h1>Some initial content</h1>"
})
};
</script>
多个编辑器并存实例
<template>
<div id="app">
<vue-editor id="editor1" v-model="editor1Content"></vue-editor>
<vue-editor id="editor2" v-model="editor2Content"></vue-editor>
</div>
</template>
<script>
import { VueEditor } from "vue2-editor";
export default {
components: {
VueEditor
},
data() {
return {
editor1Content: "<h1>Editor 1 Starting Content</h1>",
editor2Content: "<h1>Editor 2 Starting Content</h1>"
};
}
};
</script>
自定义工具栏
<template>
<vue-editor v-model="content" :editor-toolbar="customToolbar" />
</template>
<script>
import { VueEditor } from "vue2-editor";
export default {
components: { VueEditor },
data: () => ({
content: "<h1>Html For Editor</h1>",
customToolbar: [
["bold", "italic", "underline"],
[{ list: "ordered" }, { list: "bullet" }],
["image", "code-block"]
]
})
};
</script>
两个常用方法
<vue-editor ref="editor" v-model="content" />
- 获取光标位置
let cursorPos = this.$refs.editor.quill.selection.savedRange.index
- 在光标处插入字符串或其它数据类型
this.$refs.editor.quill.insertText(this.$refs.editor.quill.selection.savedRange.index, '插入的内容');
更多用法大家可自行去查阅文档。
# 文档地址
https://www.vue2editor.com/
# 仓库地址
https://github.com/davidroyer/vue2-editor
ok,就介绍到这里。如果感兴趣的话,可以去看下哈。欢迎交流讨论~
猜你喜欢
- 2024-10-13 「干货」Deno TCP Echo Server 是怎么运行的?
- 2024-10-13 Vue.js的6个最佳表单生成器组件(vue 自定义表单组件)
- 2024-10-13 Github 上 36 个最实用的 Vue 开源库
- 2024-10-13 Vue3 插件开发详解尝鲜版「值得收藏」
- 2024-10-13 基于 Express 应用框架的技术方案选型浅谈
- 2024-10-13 超实用!基于前端vue.js生态开源项目
- 2024-10-13 细品Npm 依赖处理的进化史(npm安装依赖命令)
- 2024-10-13 Vue原来可以这样写开发效率杠杠的
- 2024-10-13 带你了解 vue-next(Vue 3.0)之 炉火纯青「实践」
- 2024-10-13 Webpack Vue瘦身,感受快到飞起的加载速度!
- 最近发表
- 标签列表
-
- cmd/c (64)
- c++中::是什么意思 (83)
- 标签用于 (65)
- 主键只能有一个吗 (66)
- c#console.writeline不显示 (75)
- pythoncase语句 (81)
- es6includes (73)
- sqlset (64)
- windowsscripthost (67)
- apt-getinstall-y (86)
- node_modules怎么生成 (76)
- chromepost (65)
- c++int转char (75)
- static函数和普通函数 (76)
- el-date-picker开始日期早于结束日期 (70)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- & (66)
- java (73)
- js数组插入 (83)
- linux删除一个文件夹 (65)
- mac安装java (72)
- eacces (67)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)