Vue 富文本编辑器插件 vue-quill-editor 坑!

Vue3 + vue-quill-editor
安装步骤:
vue3 安装vue-quill-editor

npm install @vueup/vue-quill

vue2 安装vue-quill-editor

npm install vue-quill-editor

npm安装完成之后,则是main.js引用,全局的挂载它

// 导入vue富文本编辑器
import { createApp } from 'vue';
import App from './App.vue';
import { QuillEditor } from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css'
import '@vueup/vue-quill/dist/vue-quill.bubble.css'

const app = createApp(App);
app.component('QuillEditor', QuillEditor)
app.mount("#app");

在组件中使用vue-quill-editor

<template>
<div>
  <input v-model="title" class="title" type="text">
  <input @click="saveDraft" class="saveDraft" type="button" value="保存草稿"/>
  <input class="saveDiary" type="button" value="发布日记"/>
  <quill-editor :disabled="true" theme="snow"
                id="quillEditor"
                content-type="html" :content="desc"
                style="height: 600px;"/>
</div>
</template>

<script>
export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "diary",
  data() {
    return {
      desc: "",
      title: "【无标题】",
    }
  },
  methods:{
    saveDraft(){
      console.log(document.getElementById("quillEditor"))
    }
  }
}
</script>

<style scoped>
.saveDraft{
  height: 41px;
  margin-right: 16px;
  padding: 0 16px;
  font-size: 16px;
  color: #c7c9cb;
  border: 1px solid rgb(178, 62, 255);
  border-radius: 18px;
  white-space: nowrap;
  background: none;
}
.saveDraft:hover{
  background-color: rgba(203, 203, 203, 20%);;
}
.saveDiary{
  height: 41px;
  margin-right: 16px;
  padding: 0 16px;
  font-size: 16px;
  color: #c7c9cb;
  border: 1px solid rgb(178, 62, 255);
  border-radius: 18px;
  white-space: nowrap;
  background-color: rgb(178, 62, 255);
}
.saveDiary:hover{
  background-color: rgb(178, 62, 255, 70%);
}
.title{
  width: 20%;
  border-radius: 18px;
  padding: 8px;
  padding-right: 88px;
  font-size: 18px;
  line-height: 24px;
  background: none;
  margin: 10px;
}
/* ql开头表示富文本样式设计 */
.ql-toolbar.ql-snow {
  border: 1px solid #d1d5db;
  box-sizing: border-box;
  font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
  padding: 8px;
  background-color: rgb(178, 62, 255, 70%);
}

</style>

这里说一下,我遇到的坑,首先是v-model 在这个标签上没用,我也不知道为什么,然后就是@change事件没有被触发,这就导致我拿不到这个标签里面的数据,最后实在是用了一个没有办法的办法,使用了document.getElementById 这个方法来获取它里面的数据,里面可以完整的获取用户在中写入的样式,到时候把它用v-html标签输出一下就好了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值