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

vue-quill-editor+plupload富文本編輯器實(shí)例詳解

 更新時(shí)間:2018年10月19日 13:55:50   作者:張xiao旦  
這篇文章主要介紹了vue-quill-editor+plupload富文本編輯器實(shí)例詳解,需要的朋友可以參考下

1,先給vue項(xiàng)目中下載vue-quill-editor依賴npm install vue-quill-editor --save

2,下載plupload依賴npm install plupload --save

3,在組件中分別引入對應(yīng)的js

import { quillEditor }from 'vue-quill-editor'
import '@/assets/js/crypto1/crypto/crypto.js'
import '@/assets/js/crypto1/hmac/hmac.js'
import '@/assets/js/crypto1/sha1/sha1.js'
import Base64from '@/assets/js/base64.js'
import pluploadfrom 'plupload'

4,編寫plupload上傳圖片需要的事件以及參數(shù)

let accessid = '阿里oss申請的accessid'
let accesskey = '阿里oss申請的accesskey'
let host = '阿里oss的存儲文件地址'
let bucket = 'image'
let g_dirname = ''
let g_object_name = ''
let g_object_name_type = ''
var timestamp
let now = timestamp = Date.parse(new Date())/ 1000
let pos = ''
let suffix = ''
var policyText = {
'expiration': '2020-01-01T12:00:00.000Z',// 設(shè)置該P(yáng)olicy的失效時(shí)間,超過這個(gè)失效時(shí)間之后,就沒有辦法通過這個(gè)policy上傳文件了
 'conditions': [
['content-length-range',0,1048576000]// 設(shè)置上傳文件的大小限制
 ]
}
var policyBase64 = Base64.encode(JSON.stringify(policyText))
let message = policyBase64
var bytes = Crypto.HMAC(Crypto.SHA1,message,accesskey, {asBytes: true})
var signature = Crypto.util.bytesToBase64(bytes)
// 選擇上傳名字是本地文件名字還是隨機(jī)文件名字
function check_object_radio () {
g_object_name_type = 'random_name'
}
// 默認(rèn)是上傳到根目錄
function get_dirname () {
g_dirname = 'image/'
}
// 獲得隨機(jī)的字符串
function random_string (len) {
len = len || 32
 var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
 var maxPos = chars.length
 var pwd = ''
 for (var i = 0;i < len;i++) {
pwd += chars.charAt(Math.floor(Math.random()* maxPos))
}
return pwd
}
// 獲取文件后綴
function get_suffix (filename) {
pos = filename.lastIndexOf('.')
suffix = ''
 if (pos !== -1) {
suffix = filename.substring(pos)
}
return suffix
}
// 獲取文件名字
function calculate_object_name (filename) {
if (g_object_name_type === 'local_name') {
g_object_name += filename
 }else if (g_object_name_type === 'random_name') {
suffix = get_suffix(filename)
g_object_name = random_string(10)+ new Date().getTime()+ suffix
  // g_object_name = filename
 }
return ''
}
function get_uploaded_object_name (filename) {
if (g_object_name_type === 'local_name') {
var tmp_name = g_object_name
  tmp_name = tmp_name.replace(filename,filename)
return tmp_name
 }else if (g_object_name_type === 'random_name') {
return g_object_name
 }
}
// 設(shè)置上傳參數(shù)
function set_upload_param (up,filename,ret) {
// g_object_name = g_dirname
 if (filename !== '') {
suffix = get_suffix(filename)
calculate_object_name(filename)
}
let new_multipart_params = {
'Filename': g_dirname + g_object_name,
'key': g_dirname + g_object_name,
'policy': policyBase64,
'OSSAccessKeyId': accessid,
'success_action_status': '200',// 讓服務(wù)端返回200,不然,默認(rèn)會(huì)返回204
  'signature': signature
 }
console.log(g_object_name)
up.setOption({
'url': host,
'multipart_params': new_multipart_params
 })
up.start()
}
const toolbarOptions = [
['bold','italic','underline','strike'],// toggled buttons
 ['blockquote','code-block'],
[{'header': 1}, {'header': 2}],// custom button values
 [{'list': 'ordered'}, {'list': 'bullet'}],
[{'script': 'sub'}, {'script': 'super'}],// superscript/subscript
 [{'indent': '-1'}, {'indent': '+1'}],// outdent/indent
 [{'direction': 'rtl'}],// text direction
 [{'size': ['small',false,'large','huge']}],// custom dropdown
 [{'header': [1,2,3,4,5,6,false]}],
[{'color': []}, {'background': []}],// dropdown with defaults from theme
 [{'font': []}],
[{'align': []}],
['link','image'],
['clean']// remove formatting button
]
export default {
name: 'AddNotice',
components: {
quillEditor
},
data () {
return {
loading: false,
textarea_name: '',
textarea_nei: '',
content: null,
editorOption:{
placeholder: '',
theme: 'snow',// or 'bubble'
      modules: {
toolbar: {
container: toolbarOptions,// 工具欄
        handlers: {
'image': function (value) {
if (value) {
// alert(1)
           document.querySelector('#selectfiles').click()
}else {
this.quill.format('image',false);
}
}
}
}
}
}
}
},
props: {
Notice_id: Number,
AddNotice_id: Number
  },
watch: {},
methods: {
data_qing () {
this.textarea_name = ''
    this.content = ''
   },
AddNoticeOff () {
this.$emit('AddNoticeOff')
},
gonggao_push () {
this.loading = true
    let data = {
token: this.token(),
id: this.AddNotice_id,
match_id: this.Notice_id,
title: this.textarea_name,
content: this.content
    }
this.$axios.post('/match/Notice/NoticeSave',this.$qs.stringify(data))
.then((res)=> {
this.loading = false
      console.log(res)
if (res.data.code === '200') {
this.$emit('AddNoticeOff')
this.$emit('notice_ajax',0)
}
}).catch((err)=> {
this.loading = false
     console.log(err)
})
},
escape2Html (str) {
var arrEntities = {'lt': '<','gt': '>','nbsp': ' ','amp': '&','quot': '"'}
return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function (all,t) {
return arrEntities[t]
})
},
data_zhan () {
let data = {
token: this.token(),
id: this.AddNotice_id
    }
this.$axios.post('/match/Notice/NoticeInfo',this.$qs.stringify(data))
.then((res)=> {
let new_data = res.data.data
      if (res.data.code === '200') {
this.textarea_name = new_data.title
       this.content = this.escape2Html(new_data.content)
console.log(this.escape2Html(new_data.content))
}
}).catch((err)=> {
console.log(err)
})
}
},
computed: {
},
created () {
},
mounted () {
var that = this
   var uploader = new plupload.Uploader({
runtimes: 'html5,flash,silverlight,html4',
browse_button: 'selectfiles',
multi_selection: true,
// container: document.getElementById('container'),
    flash_swf_url: './../assets/plupload-2.1.2/js/Moxie.swf',
silverlight_xap_url: './../assets/plupload-2.1.2/js/Moxie.xap',
url: host,
init: {
PostInit: function () {
console.log(7777)
},
QueueChanged: function (up) {// 數(shù)組變化是發(fā)生
      console.log(up)
},
FileFiltered: function (up,files) {
var fileSize = (Math.round(files.size * 100 / (1024 * 1024))/ 100).toString()// MB
      if (fileSize > 10) {
uploader.removeFile(files)
}
},
// 圖片成功添加到上傳隊(duì)列中后的事件
     FilesAdded: function (up,files) {
console.log(111)
plupload.each(files,function (v,i) {
})
console.log(files)
set_upload_param(uploader,'',false)
},
BeforeUpload: function (up,file) {
console.log(3333)
check_object_radio()
get_dirname()
set_upload_param(up,file.name,true)
},
UploadProgress: function (up,file) {
console.log(file.percent)// 進(jìn)度條設(shè)置
     },
FileUploaded: function (up,file,info) {
console.log(555)
// 獲取富文本組件實(shí)例
      console.log(that.$refs)
let quill = that.$refs.myQuillEditor.quill
if (info.status === 200) {
console.log(get_uploaded_object_name(file.name))
let url = host+'/'+g_dirname+get_uploaded_object_name(file.name)
// 獲取光標(biāo)所在位置
       let length = quill.getSelection().index;
// 插入圖片 res.info為服務(wù)器返回的圖片地址
       quill.insertEmbed(length,'image',url)
// 調(diào)整光標(biāo)到最后
       quill.setSelection(length + 1)
}else {
this.$message.error('圖片插入失敗')
}
},
Error: function (up,err) {
// document.getElementById('console').appendChild(document.createTextNode("\nError xml:" + err.response))
     }
}
})
uploader.init()
},
destroyed () {
}
}

總結(jié)

以上所述是小編給大家介紹的vue-quill-editor+plupload富文本編輯器實(shí)例詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • VUE項(xiàng)目中加載已保存的筆記實(shí)例方法

    VUE項(xiàng)目中加載已保存的筆記實(shí)例方法

    在本篇文章里小編給大家整理了一篇關(guān)于VUE項(xiàng)目中加載已保存的筆記實(shí)例方法,有興趣的讀者們可以參考下。
    2019-09-09
  • 在Vue中使用CSS3實(shí)現(xiàn)內(nèi)容無縫滾動(dòng)的示例代碼

    在Vue中使用CSS3實(shí)現(xiàn)內(nèi)容無縫滾動(dòng)的示例代碼

    這篇文章主要介紹了在Vue中使用CSS3實(shí)現(xiàn)內(nèi)容無縫滾動(dòng)的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • 一篇文章,教你學(xué)會(huì)Vue CLI 插件開發(fā)

    一篇文章,教你學(xué)會(huì)Vue CLI 插件開發(fā)

    這篇文章主要介紹了Vue CLI插件開發(fā),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • 記一次vue-webpack項(xiàng)目優(yōu)化實(shí)踐詳解

    記一次vue-webpack項(xiàng)目優(yōu)化實(shí)踐詳解

    這篇文章主要介紹了記一次vue-webpack項(xiàng)目優(yōu)化實(shí)踐,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-02-02
  • 使用Element-UI的el-tabs組件,瀏覽器卡住了的問題及解決

    使用Element-UI的el-tabs組件,瀏覽器卡住了的問題及解決

    這篇文章主要介紹了使用Element-UI的el-tabs組件,瀏覽器卡住了的問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue3如何自定義js文件(插件或配置)

    vue3如何自定義js文件(插件或配置)

    這篇文章主要介紹了vue3如何自定義js文件(插件或配置),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue面試??贾甤omputed是如何實(shí)現(xiàn)的

    vue面試??贾甤omputed是如何實(shí)現(xiàn)的

    對于每天都在用的計(jì)算屬性(computed),小編猜大家肯定也想窺探其奧妙與原理對吧,所以這篇文章就來講講computed是如何實(shí)現(xiàn)的吧,感興趣的小伙伴可以學(xué)習(xí)一下
    2023-08-08
  • element-plus中如何實(shí)現(xiàn)按需導(dǎo)入與全局導(dǎo)入

    element-plus中如何實(shí)現(xiàn)按需導(dǎo)入與全局導(dǎo)入

    本文主要介紹了element-plus中如何實(shí)現(xiàn)按需導(dǎo)入與全局導(dǎo)入,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • vue3中element-plus表格搜索過濾數(shù)據(jù)

    vue3中element-plus表格搜索過濾數(shù)據(jù)

    本文主要介紹了vue3中element-plus表格搜索過濾數(shù)據(jù),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-03-03
  • vue集成openlayers問題

    vue集成openlayers問題

    這篇文章主要介紹了vue集成openlayers問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01

最新評論

修水县| 宿迁市| 隆林| 柳州市| 甘谷县| 新和县| 西乌| 西藏| 大足县| 合水县| 大竹县| 柘城县| 德兴市| 阳城县| 太白县| 新丰县| 南昌县| 清丰县| 建阳市| 集贤县| 永年县| 红安县| 汾阳市| 吉木萨尔县| 宾川县| 肇庆市| 河北区| 宝兴县| 张家口市| 汾阳市| 潞西市| 龙井市| 大名县| 江津市| 临江市| 阿合奇县| 曲阜市| 隆子县| 高唐县| 威信县| 健康|