由于上傳地址問題,需要自定義上傳按鈕,效果如圖

由于在頁里面沒有操作dom,所以想到了用vue的 自定義事件綁定$emit 、$on來把點擊事件傳遞給ueditor。
首先是給ueditor添加自定義按鈕:
1,打開ueditor.all.js,找到btnCmds,大概在27854行,如下圖,在數組添加一個自定義的按鈕名稱,我寫的是"love"

ueditor.all.js
2,給按鈕添加事件
還是在ueditor.all.js文件內找到commands指令 給剛才定義的按鈕擴展事件,如下:

給按鈕添加事件
我這里綁定的事件在vue里面已經定義好了 這里用$emit 綁定上去,然后在頁面里面監聽。bus是自定義的vue實例,因為整個項目是結合vue在使用。
3.給按鈕添加圖標icon
打開themes/default/css/ueditor.css.在文件下面添加即可,如下:
.edui-default .edui-toolbar .edui-for-love .edui-icon { background: url(../images/video.png) no-repeat 50% 50%;}這里的.edui-for-love后面的love就是剛才定義按鈕的名稱,由于我所有按鈕都重寫樣式了,所以全部采用覆蓋了;

給按鈕添加圖標
4. 頁面監聽點擊事件
這里的內容就是vue的基礎了,可以自己看文檔,簡單如下

先給頁面定義一個元素添加綁定事件

然后監聽ueditor傳遞過來的點擊事件showUpload

在methods里面定義showUpload事件(這里命名重復了 無所謂)
這樣 ,自定義上傳按鈕已經完成了。
下面給大家介紹vue項目中使用ueditor的例子
以vue-cli生成的項目為例
1.static文件夾下先放入ueditor文件
2.index.html添加如下代碼
<script type="text/javascript" charset="utf-8" src="static/ueditor/ueditor.config.js"></script><script type="text/javascript" charset="utf-8" src="static/ueditor/ueditor.all.min.js"></script>
3.webpack.base.conf.js添加如下配置
externals: { 'UE': 'UE', },4.index.html中添加
<script type="text/javascript"> window.UEDITOR_HOME_URL = "/static/ueditor/";//配置路徑設定為UEditor所放的位置</script>
5.editor組件
<template> <div> <mt-button @click="geteditor()" type="danger">獲取</mt-button> <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script> </div></template><script>const UE = require('UE');// eslint-disable-lineexport default { name: 'editorView', data: () => ( { editor: null, } ), methods: { geteditor() { console.log(this.editor.getContent()); }, }, mounted() { this.editor = UE.getEditor('editor'); }, destroyed() { this.editor.destroy(); },};</script><style></style>總結
以上所述是小編給大家介紹的vue項目中應用ueditor自定義上傳按鈕功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答