用vue 和vue-quill-editor 生成一个可以插入表格的富文本编辑器,默认输入框占用10行
时间: 2023-08-25 20:09:37 浏览: 872
好的,首先安装 `vue-quill-editor` 和 `quill`:
```bash
npm install vue-quill-editor quill --save
```
然后在你的 Vue 组件中引入并注册 `vue-quill-editor`:
```html
<template>
<div>
<quill-editor v-model="content" ref="myQuillEditor" :options="editorOption"></quill-editor>
</div>
</template>
<script>
import QuillEditor from 'vue-quill-editor'
export default {
components: {
QuillEditor
},
data() {
return {
content: '',
editorOption: {
theme: 'snow', // 主题
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'], // 加粗、斜体、下划线、删除线
['blockquote', 'code-block'], // 引用、代码块
[{ 'header': 1 }, { 'header': 2 }], // 标题
[{ 'list': 'ordered' }, { 'list': 'bullet' }], // 有序列表、无序列表
[{ 'script': 'sub' }, { 'script': 'super' }], // 上下标
[{ 'indent': '-1' }, { 'indent': '+1' }], // 缩进
[{ 'direction': 'rtl' }], // 文本方向
[{ 'size': ['small', false, 'large', 'huge'] }], // 字体大小
[{ 'header': [1, 2, 3, 4, 5, 6, false] }], // 标题大小
[{ 'color': [] }, { 'background': [] }], // 字体颜色、背景颜色
[{ 'font': [] }], // 字体
[{ 'align': [] }], // 对齐方式
['clean'], // 清除格式
['table'] // 添加表格
]
}
}
}
},
mounted() {
this.$refs.myQuillEditor.quill.root.style.height = '10rem'; // 设置默认高度
}
}
</script>
```
以上是一个简单的富文本编辑器,包含了可以插入表格的功能。同时,我们使用了 `mounted` 钩子来设置默认高度为 10 行,你可以根据自己的需要进行调整。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)