<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

        Vue項(xiàng)目中quill-editor帶樣式編輯器的使用方法

        來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:33:22
        文檔

        Vue項(xiàng)目中quill-editor帶樣式編輯器的使用方法

        Vue項(xiàng)目中quill-editor帶樣式編輯器的使用方法:vue-quill-editor默認(rèn)插入圖片是直接將圖片轉(zhuǎn)為base64再放入內(nèi)容中,如果圖片比較大的話,富文本的內(nèi)容就會很大。 插入視頻是直接彈框輸入U(xiǎn)RL地址,某些需求下我們需要讓用戶去本地選擇自己的視頻,我們可以通過vue-quill-editor內(nèi)部的某些方法進(jìn)行更
        推薦度:
        導(dǎo)讀Vue項(xiàng)目中quill-editor帶樣式編輯器的使用方法:vue-quill-editor默認(rèn)插入圖片是直接將圖片轉(zhuǎn)為base64再放入內(nèi)容中,如果圖片比較大的話,富文本的內(nèi)容就會很大。 插入視頻是直接彈框輸入U(xiǎn)RL地址,某些需求下我們需要讓用戶去本地選擇自己的視頻,我們可以通過vue-quill-editor內(nèi)部的某些方法進(jìn)行更

        vue-quill-editor默認(rèn)插入圖片是直接將圖片轉(zhuǎn)為base64再放入內(nèi)容中,如果圖片比較大的話,富文本的內(nèi)容就會很大。

        插入視頻是直接彈框輸入U(xiǎn)RL地址,某些需求下我們需要讓用戶去本地選擇自己的視頻,我們可以通過vue-quill-editor內(nèi)部的某些方法進(jìn)行更改

        該方法使用了 element-ui 和 文件上傳七牛

        一、npm 安裝 vue-quill-editor

        二、在main.js中引入

        import VueQuillEditor from 'vue-quill-editor'
        Vue.use(VueQuillEditor)
        
        
         

        HTML部分:為編輯器綁定各個(gè)API事件,定義一個(gè)隱藏的input框,用于點(diǎn)擊圖片或者視頻圖標(biāo)上傳文件

        <template>
         <div>
         <!-- quill-editor插件標(biāo)簽 分別綁定各個(gè)事件-->
         <quill-editor v-model="content" ref="myQuillEditor" :options="editorOption" @blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
         @change="onEditorChange($event)">
         </quill-editor>
         <div class="limit">當(dāng)前已輸入 <span>{{nowLength}}</span> 個(gè)字符,您還可以輸入 <span>{{SurplusLength}}</span> 個(gè)字符。</div>
         <!-- 文件上傳input 將它隱藏-->
         <el-upload class="upload-demo" :action="qnLocation" :before-upload='beforeUpload' :data="uploadData" :on-success='upScuccess'
         ref="upload" style="display:none">
         <el-button size="small" type="primary" id="imgInput" v-loading.fullscreen.lock="fullscreenLoading" element-loading-text="插入中,請稍候">點(diǎn)擊上傳</el-button>
         </el-upload>
         </el-table>
         </div>
        </template>
        

        CSS部分:

        .quill-editor {
         height: 745px;
        
         .ql-container {
         height: 680px;
         }
        }
        
        .limit {
         height: 30px;
         border: 1px solid #ccc;
         line-height: 30px;
         text-align: right;
        
         span {
         color: #ee2a7b;
         }
        }
        
        .ql-snow .ql-editor img {
         max-width: 480px;
        }
        
        .ql-editor .ql-video {
         max-width: 480px;
        }
        
        

         JS部分:

        import Vue from 'util/vueExt'
        import { Component } from 'vue-property-decorator'
        import * as Template from './editor.vue'
        import * as Quill from 'quill' // 引入編輯器
        
        const STATICDOMAIN = '//ss.yidejia.com/'
        const STATVIDEO = '//flv.yidejia.com/'
        
        @Component({
         mixins: [Template]
        })
        export default class Editor extends Vue {
         content = '' // 文章內(nèi)容
         editorOption = {} // 編輯器選項(xiàng)
         addRange: any = new Array()
         uploadData = {}
         photoUrl = '' // 上傳圖片地址
         uploadType = '' // 上傳的文件類型(圖片、視頻)
         fullscreenLoading = false
        
         $refs: {
         myQuillEditor: any,
         imgInput: any
         }
        
         get nowLength() {
         return this.content.length
         }
        
         get SurplusLength() { // 計(jì)算屬性 獲得當(dāng)前輸入字符長度
         let num = 10000 - Number(this.content.length)
         if (num > 0) {
         return num
         } else {
         return 0
         }
         }
        
         // 上傳七牛的actiond地址
         get qnLocation() {
         if (location.protocol === 'http:') {
         return 'http://up-z0.qiniu.com'
         }
         return 'https://up-z0.qbox.me'
         }
        
         // 圖片上傳前獲得數(shù)據(jù)token數(shù)據(jù)
         qnUpload(file) {
         this.fullscreenLoading = true
         const suffix = file.name.split('.')
         const ext = suffix.splice(suffix.length - 1, 1)[0]
         console.log(this.uploadType)
         if (this.uploadType === 'image') { // 如果是點(diǎn)擊插入圖片
         return this.api.getQNToken().then(res => {
         this.uploadData = {
         key: `image/${suffix.join('.')}_${new Date().getTime()}.${ext}`,
         token: res
         }
         })
         } else if (this.uploadType === 'video') { // 如果是點(diǎn)擊插入視頻
         return this.api.getVideoQNToken().then(res => {
         this.uploadData = {
         key: `video/${suffix.join('.')}_${new Date().getTime()}.${ext}`,
         token: res
         }
         })
         }
         }
        
         // 圖片上傳之前調(diào)取的函數(shù)
         beforeUpload(file) {
         return this.qnUpload(file)
         }
        
         // 圖片上傳成功回調(diào) 插入到編輯器中
         upScuccess(e, file, fileList) {
         this.fullscreenLoading = false
         let vm = this
         let url = ''
         if (this.uploadType === 'image') { // 獲得文件上傳后的URL地址
         url = STATICDOMAIN + e.key
         } else if (this.uploadType === 'video') {
         url = STATVIDEO + e.key
         }
         if (url != null && url.length > 0) { // 將文件上傳后的URL地址插入到編輯器文本中
         let value = url
         vm.addRange = vm.$refs.myQuillEditor.quill.getSelection()
         value = value.indexOf('http') !== -1 ? value : 'http:' + value
         vm.$refs.myQuillEditor.quill.insertEmbed(vm.addRange !== null ? vm.addRange.index : 0, vm.uploadType, value, Quill.sources.USER) // 調(diào)用編輯器的 insertEmbed 方法,插入U(xiǎn)RL
         } else {
         (<any>this).$message.error(`${vm.uploadType}插入失敗`)
         }
         this.$refs['upload'].clearFiles() // 插入成功后清除input的內(nèi)容
         }
        
         // 點(diǎn)擊圖片ICON觸發(fā)事件
         imgHandler(state) {
         this.addRange = this.$refs.myQuillEditor.quill.getSelection()
         if (state) {
         let fileInput = document.getElementById('imgInput')
         fileInput.click() // 加一個(gè)觸發(fā)事件
         }
         this.uploadType = 'image'
         }
        
         // 點(diǎn)擊視頻ICON觸發(fā)事件
         videoHandler(state) {
         this.addRange = this.$refs.myQuillEditor.quill.getSelection()
         if (state) {
         let fileInput = document.getElementById('imgInput')
         fileInput.click() // 加一個(gè)觸發(fā)事件
         }
         this.uploadType = 'video'
         }
        
         // 編輯器光標(biāo)離開 將編輯器內(nèi)容發(fā)射給父組件
         onEditorBlur(editor) {
         this.$emit('getValue', this.content)
         }
        
         // 編輯器獲得光標(biāo)
         onEditorFocus(editor) {
         editor.enable(true) // 實(shí)現(xiàn)達(dá)到上限字符可刪除
         }
        
         // 編輯器文本發(fā)生變化
         onEditorChange({ editor, html, text }) {
         let textLength = text.length
         if (textLength > 10000) {
         (<any>this).$message.error('最多輸入10000個(gè)字符')
         editor.enable(false)
         }
         this.$emit('getValue', this.content)
         }
        
         // 清除編輯器內(nèi)容
         callMethod() {
         this.content = ''
         }
        
         // 頁面加載后執(zhí)行 為編輯器的圖片圖標(biāo)和視頻圖標(biāo)綁定點(diǎn)擊事件
         mounted() {
         // 為圖片ICON綁定事件 getModule 為編輯器的內(nèi)部屬性
         this.$refs.myQuillEditor.quill.getModule('toolbar').addHandler('image', this.imgHandler)
         this.$refs.myQuillEditor.quill.getModule('toolbar').addHandler('video', this.videoHandler) // 為視頻ICON綁定事件
         }
        }
        

        相關(guān)參考鏈接:

        vue-quill-editor實(shí)現(xiàn)圖片上傳功能

        vue-quill-editor API文檔地址

        本文已被整理到了《Vue.js前端組件學(xué)習(xí)教程》,歡迎大家學(xué)習(xí)閱讀。

        關(guān)于vue.js組件的教程,請大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Vue項(xiàng)目中quill-editor帶樣式編輯器的使用方法

        Vue項(xiàng)目中quill-editor帶樣式編輯器的使用方法:vue-quill-editor默認(rèn)插入圖片是直接將圖片轉(zhuǎn)為base64再放入內(nèi)容中,如果圖片比較大的話,富文本的內(nèi)容就會很大。 插入視頻是直接彈框輸入U(xiǎn)RL地址,某些需求下我們需要讓用戶去本地選擇自己的視頻,我們可以通過vue-quill-editor內(nèi)部的某些方法進(jìn)行更
        推薦度:
        標(biāo)簽: VUE 編輯器 樣式
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 青草草色A免费观看在线| 免费又黄又爽又猛大片午夜| 久久亚洲免费视频| 亚洲AV永久无码精品一百度影院| 国产乱妇高清无乱码免费| 亚洲中文字幕久久精品无码APP | 久久夜色精品国产亚洲av | 免费观看91视频| 亚洲国产成人久久精品影视| 久久久久久久岛国免费播放| 婷婷亚洲久悠悠色悠在线播放| 久久aⅴ免费观看| 亚洲另类春色国产精品| 女性自慰aⅴ片高清免费| 国产亚洲欧美在线观看| 亚洲另类少妇17p| 免费看一区二区三区四区| 亚洲高清资源在线观看| 最近最好的中文字幕2019免费| 亚洲6080yy久久无码产自国产| 亚洲AV无码乱码在线观看牲色| xxxx日本在线播放免费不卡| 好看的亚洲黄色经典| 国产91免费视频| 狠狠综合亚洲综合亚洲色| 中文字幕亚洲一区| 日本人的色道免费网站| 老司机亚洲精品影院在线观看| 国产亚洲av人片在线观看| 五月亭亭免费高清在线| 无码天堂亚洲国产AV| 亚洲AV无码一区二区三区系列| 免费无码精品黄AV电影| 四虎永久在线精品免费一区二区 | 亚洲日本乱码一区二区在线二产线 | 中国性猛交xxxxx免费看| 亚洲国产精品久久久久秋霞影院| 成年在线网站免费观看无广告| 精选影视免费在线 | 亚洲一区二区无码偷拍| 亚洲日韩一页精品发布|