国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue3使用quill富文本編輯器,保姆級教程,富文本踩坑解決

這篇具有很好參考價(jià)值的文章主要介紹了vue3使用quill富文本編輯器,保姆級教程,富文本踩坑解決。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

vue3使用quilleditor

本文是封裝成組件使用

先放效果圖
vue3使用quill富文本編輯器,保姆級教程,富文本踩坑解決

// 安裝插件
npm install @vueup/vue-quill@alpha --save
// 局部引入
import { QuillEditor } from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css'

先封裝組件,建立如下目錄
vue3使用quill富文本編輯器,保姆級教程,富文本踩坑解決
全部代碼如下,

<template>
  <div>
  	<!-- 此處注意寫法v-model:content -->
    <QuillEditor ref="myQuillEditor"
      theme="snow"
      v-model:content="content"
      :options="data.editorOption"
      contentType="html"
      @update:content="setValue()"
    />
    <!-- 使用自定義圖片上傳 -->
    <input type="file" hidden accept=".jpg,.png" ref="fileBtn" @change="handleUpload" />
  </div>
</template>

<script setup>
import { QuillEditor } from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css'
import { reactive, onMounted, ref, toRaw, watch } from 'vue'

const props = defineProps(['value'])
const emit = defineEmits(['updateValue'])
const content = ref('')
const myQuillEditor = ref()
// 通過watch監(jiān)聽回顯,筆者這邊使用v-model:content 不能正?;仫@
watch(() => props.value, (val) => {
  toRaw(myQuillEditor.value).setHTML(val)
}, { deep: true })
const fileBtn = ref()
const data = reactive({
  content: '',
  editorOption: {
    modules: {
      toolbar: [
        ['bold', 'italic', 'underline', 'strike'],
        [{ 'size': ['small', false, 'large', 'huge'] }],
        [{ 'font': [] }],
        [{ 'align': [] }],
        [{ 'list': 'ordered' }, { 'list': 'bullet' }],
        [{ 'indent': '-1' }, { 'indent': '+1' }],
        [{ 'header': 1 }, { 'header': 2 }],
        ['image'],
        [{ 'direction': 'rtl' }],
        [{ 'color': [] }, { 'background': [] }]
      ]
    },
    placeholder: '請輸入內(nèi)容...'
  }
})
const imgHandler = (state) => {
  if (state) {
    fileBtn.value.click()
  }
}
// 拋出更改內(nèi)容,此處避免出錯(cuò)直接使用文檔提供的getHTML方法
const setValue = () => {
  const text = toRaw(myQuillEditor.value).getHTML()
}
const handleUpload = (e) => {
  const files = Array.prototype.slice.call(e.target.files)
  // console.log(files, "files")
  if (!files) {
    return
  }
  const formdata = new FormData()
  formdata.append('file', files[0])
  backsite.uploadFile(formdata)  // 此處使用服務(wù)端提供上傳接口
    .then(res => {
      if (res.data.url) {
        const quill = toRaw(myQuillEditor.value).getQuill()
        const length = quill.getSelection().index
        quill.insertEmbed(length, 'image', res.data.url)
        quill.setSelection(length + 1)
      }
    })
}
// 初始化編輯器
onMounted(() => {
  const quill = toRaw(myQuillEditor.value).getQuill()
  if (myQuillEditor.value) {
    quill.getModule('toolbar').addHandler('image', imgHandler)
  }
})
</script>
<style scoped lang="scss">
// 調(diào)整樣式
:deep(.ql-editor) {
  min-height: 180px;
}
:deep(.ql-formats) {
  height: 21px;
  line-height: 21px;
}
</style>

使用

<template>
  <div class="page">
	<Editor :value="emailForm.msg" @updateValue="getMsg" />
  </div>
</template>

<script setup>
import Editor from '@/components/Editor/index.vue'

const emailForm = reactive({
  test_msg: ''
})
const getMsg = (val) => {
  emailForm.msg = val
}
</script>

本文是第二個(gè)頁面使用這個(gè)富文本編輯器有可能watch監(jiān)聽中找不到ref,如果不能正常使用可以稍微改裝下在onMounted里賦值然后在setValue里拋出就好

<template>
  <div>
    <QuillEditor ref="myQuillEditor"
      theme="snow"
      v-model:content="content"
      :options="data.editorOption"
      contentType="html"
      @update:content="setValue()"
    />
    <!-- 使用自定義圖片上傳 -->
    <input type="file" hidden accept=".jpg,.png" ref="fileBtn" @change="handleUpload" />
  </div>
</template>

<script setup>
import { QuillEditor } from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css'
import { reactive, onMounted, ref, toRaw, watch } from 'vue'
// import { backsite } from '@/api'

const props = defineProps(['value'])
const emit = defineEmits(['updateValue'])
const content = ref('')
const myQuillEditor = ref()
// watch(() => props.value, (val) => {
//   console.log(toRaw(myQuillEditor.value))
//   toRaw(myQuillEditor.value).setHTML(val)
// }, { deep: true })
const fileBtn = ref()
const data = reactive({
  content: '',
  editorOption: {
    modules: {
      toolbar: [
        ['bold', 'italic', 'underline', 'strike'],
        [{ 'size': ['small', false, 'large', 'huge'] }],
        [{ 'font': [] }],
        [{ 'align': [] }],
        [{ 'list': 'ordered' }, { 'list': 'bullet' }],
        [{ 'indent': '-1' }, { 'indent': '+1' }],
        [{ 'header': 1 }, { 'header': 2 }],
        ['image'],
        [{ 'direction': 'rtl' }],
        [{ 'color': [] }, { 'background': [] }]
      ]
    },
    placeholder: '請輸入內(nèi)容...'
  }
})
const imgHandler = (state) => {
  if (state) {
    fileBtn.value.click()
  }
}
const setValue = () => {
  const text = toRaw(myQuillEditor.value).getHTML()
  emit('updateValue', text)
}
const handleUpload = (e) => {
  const files = Array.prototype.slice.call(e.target.files)
  // console.log(files, "files")
  if (!files) {
    return
  }
  const formdata = new FormData()
  formdata.append('file', files[0])
  // backsite.uploadFile(formdata)
  //   .then(res => {
  //     if (res.data.url) {
  //       const quill = toRaw(myQuillEditor.value).getQuill()
  //       const length = quill.getSelection().index
  //       // 插入圖片,res為服務(wù)器返回的圖片鏈接地址
  //       quill.insertEmbed(length, 'image', res.data.url)
  //       // 調(diào)整光標(biāo)到最后
  //       quill.setSelection(length + 1)
  //     }
  //   })
}
onMounted(() => {
  const quill = toRaw(myQuillEditor.value).getQuill()
  if (myQuillEditor.value) {
    quill.getModule('toolbar').addHandler('image', imgHandler)
  }
  toRaw(myQuillEditor.value).setHTML(props.value)
})
</script>
<style scoped lang="scss">
:deep(.ql-editor) {
  min-height: 180px;
}
:deep(.ql-formats) {
  height: 21px;
  line-height: 21px;
}
</style>

保姆級教程,有問題歡迎提出文章來源地址http://www.zghlxwxcb.cn/news/detail-514829.html

到了這里,關(guān)于vue3使用quill富文本編輯器,保姆級教程,富文本踩坑解決的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • vue-quill-editor富文本編輯器使用步驟

    vue-quill-editor富文本編輯器使用步驟

    首先放上效果圖 目錄 1.安裝 2.引入到項(xiàng)目中 3.在頁面上寫組件 4.配置option 5.給工具欄鼠標(biāo)懸停加上中文釋義 6.上傳圖片到七牛云 7.自定義控制圖片大小 1.安裝 2.引入到項(xiàng)目中 ????????有兩種掛載方式: 全局掛載 和 在組件中掛載,根據(jù)自己的項(xiàng)目需求選擇,一般用到富文

    2024年02月06日
    瀏覽(29)
  • 富文本編輯器 VUE-QUILL-EDITOR 使用教程 (最全)

    富文本編輯器 VUE-QUILL-EDITOR 使用教程 (最全)

    VUE-QUILL-EDITOR 基于 QUILL、適用于 VUE 的富文本編輯器,支持服務(wù)端渲染和單頁應(yīng)用,非常高效簡潔。 在全局中引入 在指定的 vue 文件中引入 到這里一個(gè)默認(rèn)的富文本編輯器已經(jīng)導(dǎo)入使用了,如下圖所視! 一般的,我們在使用的時(shí)候并不需要這么多功能,可以適當(dāng)?shù)膶庉嬈髋?/p>

    2024年02月04日
    瀏覽(20)
  • Vue +vue-quill-editor+ Element UI使用富文本編輯器,上傳圖片,上傳視頻

    Vue +vue-quill-editor+ Element UI使用富文本編輯器,上傳圖片,上傳視頻

    如果你們有問題,可以發(fā)評論提問,我看見一定回復(fù)!?。。?! 一、基本使用 1、下載vue-quill-editor組件 2、引入· 富文本組件 方式一:全局引入 (在 main.js 文件中) 方式二:按需引入 (在 單個(gè)組件 中引用) 3、工具欄相關(guān)配置 4、設(shè)置工具欄中文提示 5、修改vue-quill-editor字體

    2024年02月08日
    瀏覽(117)
  • 簡版的富文本編輯器、VUE+ElementUI 富文本編輯器 element ui富文本編輯器的使用(quill-editor) 不好用你來打我!全網(wǎng)醉簡單!要復(fù)雜的別來!

    簡版的富文本編輯器、VUE+ElementUI 富文本編輯器 element ui富文本編輯器的使用(quill-editor) 不好用你來打我!全網(wǎng)醉簡單!要復(fù)雜的別來!

    實(shí)現(xiàn)效果 ? 1.安裝插件 npm install vue-quill-editor --save 2.安裝成功后在package.json中查看 3.在main.js中全局引入插件 4.頁面實(shí)現(xiàn) 感謝老哥:?ElementUI生成富文本編輯器 https://blog.csdn.net/keplerm/article/details/123379511?spm=1001.2101.3001.6650.9utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCom

    2024年02月16日
    瀏覽(30)
  • 【移動(dòng)端VUE】使用富文本編輯器插件 vue-quill-editor 以及移動(dòng)端適配踩過的坑

    【移動(dòng)端VUE】使用富文本編輯器插件 vue-quill-editor 以及移動(dòng)端適配踩過的坑

    合同填寫審批意見時(shí)使用富文本編輯器填寫,支持字體較粗、修改顏色,最后審批歷史可以展示出業(yè)務(wù)填寫的效果,實(shí)現(xiàn)結(jié)果: 1. 安裝 vue-quill-editor 2、引入 - 全局引入 在 main.js 中引入插件 - 局部引入 3、使用VueQuillEditor 這里展示局部使用的代碼 然后就實(shí)現(xiàn)了產(chǎn)品想要的結(jié)果

    2023年04月08日
    瀏覽(28)
  • vue-quill-editor富文本編輯器-擴(kuò)展表格、圖片調(diào)整大小

    vue-quill-editor富文本編輯器-擴(kuò)展表格、圖片調(diào)整大小

    上篇文章已經(jīng)講到、vue-quill-editor的基本配置和圖片轉(zhuǎn)成url 這篇文章主要使用插件來完成 圖片調(diào)整大小 和 表格的插件使用( 這兩個(gè)目前quill 版本并不兼容 如果有大神解決了還望指點(diǎn) ) 參考文章: vue-quill-editor 富文本編輯器支持圖片拖拽和放大縮小_*且聽風(fēng)吟的博客-CSDN博

    2024年02月04日
    瀏覽(93)
  • element ui富文本編輯器的使用(quill-editor)

    element ui富文本編輯器的使用(quill-editor)

    可以拖拽圖片大小及其位置 為了便于大家直接使用,直接把script以及css放在一個(gè)頁面里,之際copy就可以使用 注意: 1、我是在elementUi使用的,上傳圖片以及頁面的訪問需要有登錄權(quán)限,所以我的上傳圖片視頻的組件里有:headers=“headers”,攜帶登錄權(quán)限 2、需要更改自己的上

    2024年02月03日
    瀏覽(21)
  • Vue3項(xiàng)目中使用富文本編輯器

    tinymce簡介 一、 安裝 二、使用步驟 1. 封裝組件 2. 組件中掛載 3.應(yīng)用富文本 總結(jié) TinyMCE 是一款易用、且功能強(qiáng)大的所見即所得的富文本編輯器。跟其他富文本編輯器相比,有著豐富的插件,支持多種語言,能夠滿足日常的業(yè)務(wù)需求并且免費(fèi)。 一、安裝Tinymce 注意:版本可根據(jù)

    2024年02月15日
    瀏覽(30)
  • vue3項(xiàng)目使用富文本編輯器-wangeditor

    vue3項(xiàng)目使用富文本編輯器-wangeditor

    1.下載依賴 2.插件版本 ?3.使用 引入css和組件 配置方法 模板(標(biāo)簽)中插入 效果 ?

    2024年02月09日
    瀏覽(32)
  • Vue3中快速簡單使用CKEditor 5富文本編輯器

    Vue3中快速簡單使用CKEditor 5富文本編輯器

    CKEditor 5就是內(nèi)嵌在網(wǎng)頁中的一個(gè)富文本編輯器工具 CKEditor 5開發(fā)文檔(英文):https://ckeditor.com/docs/ckeditor5/latest/index.html 接下來帶你快速熟悉CKEditor 5在Vue3中簡單使用,看最終效果圖?? 本文項(xiàng)目采用CKEditor 5定制經(jīng)典配置(ckeditor5-build-classic) + @ckeditor/ckeditor5-vue 官網(wǎng)定制,選

    2024年02月09日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包