最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2017年08月08日 11:42:16   作者:嘉爺  
這篇文章主要介紹了Vue項(xiàng)目中quill-editor帶樣式編輯器的使用方法,可以更改插入圖片和視頻,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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í)。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue El-descriptions 描述列表功能實(shí)現(xiàn)

    Vue El-descriptions 描述列表功能實(shí)現(xiàn)

    這篇文章主要介紹了Vue El-descriptions 描述列表功能實(shí)現(xiàn),Descriptions 描述列表,列表形式展示多個(gè)字段,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2024-05-05
  • vuex Module將 store 分割成模塊的操作

    vuex Module將 store 分割成模塊的操作

    這篇文章主要介紹了vuex Module將 store 分割成模塊,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • c++游戲教程使用easyx做出大飛機(jī)

    c++游戲教程使用easyx做出大飛機(jī)

    這篇文章主要為大家介紹了c++游戲教程使用easyx實(shí)現(xiàn)大飛機(jī)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • 一定要知道的 25 個(gè) Vue 技巧

    一定要知道的 25 個(gè) Vue 技巧

    這篇文章主要給大家分享將 prop 限制為類型列表、默認(rèn)內(nèi)容和擴(kuò)展點(diǎn)、使用引號觀察嵌套值、知道何時(shí)使用 v-if、單作用域 slot 的簡寫、有條件地渲染slot等25 個(gè)Vue 技巧,下文是下相關(guān)資料,需要的朋友可以參考一下
    2021-11-11
  • vue+Element-ui前端實(shí)現(xiàn)分頁效果

    vue+Element-ui前端實(shí)現(xiàn)分頁效果

    這篇文章主要為大家詳細(xì)介紹了vue+Element-ui前端實(shí)現(xiàn)分頁效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • 使用FileReader API創(chuàng)建Vue文件閱讀器組件

    使用FileReader API創(chuàng)建Vue文件閱讀器組件

    這篇文章主要介紹了使用FileReader API創(chuàng)建一個(gè)Vue的文件閱讀器組件,需要的朋友可以參考下
    2018-04-04
  • 如何使用uniapp內(nèi)置組件webview消息傳遞詳解

    如何使用uniapp內(nèi)置組件webview消息傳遞詳解

    uni-app的web-view組件用于在應(yīng)用中打開網(wǎng)頁,并支持應(yīng)用和網(wǎng)頁之間的消息傳遞,這篇文章主要介紹了如何使用uniapp內(nèi)置組件webview消息傳遞的相關(guān)資料,需要的朋友可以參考下
    2025-02-02
  • Vue3獲取DOM節(jié)點(diǎn)的3種方式實(shí)例

    Vue3獲取DOM節(jié)點(diǎn)的3種方式實(shí)例

    Vue本來無需操作DOM來更新界面,而且Vue也不推薦我們直接操作DOM,但是我們非要拿到DOM操作DOM怎么辦,下面這篇文章主要給大家介紹了關(guān)于Vue3獲取DOM節(jié)點(diǎn)的3種方式,需要的朋友可以參考下
    2023-02-02
  • vue組件中修改組件外元素樣式的兩種解決方案

    vue組件中修改組件外元素樣式的兩種解決方案

    這篇文章主要介紹了vue組件中修改組件外元素樣式,本文給大家分享兩種解決方案幫助大家解決這樣的問題,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-05-05
  • vue實(shí)現(xiàn)輸入框只允許輸入數(shù)字

    vue實(shí)現(xiàn)輸入框只允許輸入數(shù)字

    在vue項(xiàng)目中,輸入框只允許輸入數(shù)字,現(xiàn)將自己使用的一種方法記錄,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧
    2023-11-11

最新評論

灵川县| 永丰县| 宜春市| 罗城| 洪江市| 望江县| 靖边县| 田东县| 启东市| 乐陵市| 开江县| 南投县| 崇义县| 金沙县| 千阳县| 赤水市| 安康市| 望江县| 邵武市| 汝州市| 白城市| 富蕴县| 乐昌市| 越西县| 康保县| 金沙县| 南昌市| 棋牌| 板桥市| 南丹县| 侯马市| 原阳县| 柯坪县| 安泽县| 社旗县| 中宁县| 开远市| 洮南市| 遂溪县| 青河县| 页游|