vue中使用element-tiptap

安装

npm install --save element-tiptap或者yarn add element-tiptap

main.js文件引入(全局引入)
// 引入element-tiptap
import { ElementTiptapPlugin } from 'element-tiptap';
// import element-tiptap 样式
import 'element-tiptap/lib/index.css';
//使用
Vue.use(ElementTiptapPlugin,{
  lang: 'zh',
});
在组件中使用
<template>
  <div>
    <el-tiptap
      v-model="content"
      :extensions="extensions"
      placeholder="请输入内容 …"
      width="80%"
      height="600"
    ></el-tiptap>
  </div>
</template>

<script>
	import {
	  // 需要的 extensions
	  Doc,
	  Text,
	  Paragraph,
	  Heading,
	  Bold,
	  Underline,
	  Italic,
	  Strike,
	  ListItem,
	  BulletList,
	  OrderedList,
	  Link,
	  Image,
	  Iframe,
	  CodeBlock,
	  Blockquote,
	  TodoItem,
	  TodoList,
	  TextAlign,
	  FontSize,
	  FontType,
	  SelectAll,
	  Fullscreen,
	  Print,
	  Preview,
	  TextHighlight,
	  TextColor,
	  FormatClear,
	  Table,
	  TableHeader,
	  TableCell,
	  TableRow,
	  History,
	  TrailingNode,
	  HardBreak,
	  HorizontalRule,
	  LineHeight,
	  Indent,
	} from "element-tiptap";

	export default {
		  name: "",
		  components: {},
		  props: {},
		  data() {
	   	 return {
	      extensions: [
	        new Doc(),
	        new Text(),
	        new Paragraph(),
	        new Heading({ level: 6 }),
	        new Bold({ bubble: true }), // 在气泡菜单中渲染菜单按钮
	        new Underline({ bubble: true, menubar: false }), // 在气泡菜单而不在菜单栏中渲染菜单按钮
	        new Italic(),
	        new Strike(),
	        new ListItem(),
	        new BulletList(),
	        new OrderedList(),
	        new Link(),
	        new Image(
	          // {
	          // 默认会把图片生成 base64 字符串和内容存储在一起,如果需要自定义图片上传
	          // uploadRequest(file) {
	          //   如果接口要求 Content-Type 是 multipart/form-data,则请求体必须使用 FormData
	          //   const fd = new FormData()
	          //   fd.append('image', file)
	          //   第1个 return 是返回 Promise 对象
	          //   为什么?因为 axios 本身就是返回 Promise 对象
	          //   return uploadImage(fd).then(res => {
	          //     // 这个 return 是返回最后的结果
	          //     return res.data.data.url
	          //   })
	          // } // 图片的上传方法,返回一个 Promise<url>
	        // }
	        ),
	        new Iframe(),
	        new CodeBlock(),
	        new Blockquote(),
	        new TodoItem(),
	        new TodoList(),
	        new TextAlign(),
	        new FontSize(),
	        new FontType(),
	        new SelectAll(),
	        new Fullscreen(),
	        new Print(),
	        new Preview(),
	        new TextHighlight(),
	        new TextColor(),
	        new FormatClear(),
	        new Table({ resizable: true }),
	        new TableHeader(),
	        new TableCell(),
	        new TableRow(),
	        new History(),
	        new TrailingNode(),
	        new HardBreak(),
	        new HorizontalRule(),
	        new LineHeight(),
	        new Indent(),
	      ],
	      content: "",
    };
  },
};
</script>

<style scoped lang="less">
</style>

效果图:
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

参考文档:https://github.com/Leecason/element-tiptap

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吃葡萄不吐葡萄皮嘻嘻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值