网站首页 > 知识剖析 正文
今天给小伙伴们分享一款超好用的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-11-11 Cadence中layout常用设置及快捷键
- 2024-11-11 最强推荐: Android 开发中必备的代码 Review 清单,你还不知道吗
- 2024-11-11 前端金九银十面试必备八股文宝典——HTML&CSS
- 2024-11-11 jQueryEasyUI中的拖拽事件如何使用
- 2024-11-11 6.7 PyQt5控件介绍【文本编辑框控件】-QTextEdit
- 2024-11-11 小白 AI 编程 小白程序
- 2024-11-11 如何破解字体反爬机制 反字体代码
- 2024-11-11 感受 AI 的力量——利用 Cursor 自动生成 powershell 脚本下载 TheOldNewThing 博文
- 2024-11-11 「软帝学院」java常用词汇分享第二弹
- 2024-11-11 MS-DOS信息英汉对照1.3 信息英文message
- 04-29php开发者composer使用看这一篇就够了
- 04-29引用和变量声明在不同语言中的实作
- 04-29PHP 没你想的那么差
- 04-29Ubuntu linux 上的 Nginx 和 Php 安装
- 04-29CentOS下通过yum搭建lnmp(单版本PHP)
- 04-29为什么 PHP8 是个高性能版本
- 04-29PHP8函数包含文件-PHP8知识详解
- 04-29使用无参数函数进行命令执行
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)