Simditor學習--vuejs集成simditor


嘮叨

  因為項目需要我自己研究了和集成在vue方便以后再使用,詳情官方文檔在這里。希望大家有好的建議提出讓我繼續改進。

simditor介紹

Simditor 是團隊協作工具 Tower 使用的富文本編輯器,基於jQuery開發。

相比傳統的編輯器它的特點是:

  1. 功能精簡,加載快速
  2. 輸出格式化的標准 HTML
  3. 每一個功能都有非常優秀的使用體驗
  4. 兼容的瀏覽器:IE10+、Chrome、Firefox、Safari。

Vue集成

   下載:

 點擊這里下載的壓縮文件。你也可以通過bower或者npm安裝simditor:

  • $ npm install simditor
  • $ bower install simditor

這里主要講的集成到vuejs,其他引入方式自行翻閱官網。

  初始化:

html模版如下:

<textarea :id="textnames" >
    <p>{{value}}</p>
</textarea>

我們只需要他接收父組件的值和傳值回父組件,所以不需要太復雜。

js模版如下:

 

import Simditor from 'simditor'
    export default {
        props: ['value'],
        data() {
            return {
                textnames: new Date().getTime(),//這里防止多個富文本發生沖突
                editor:'',//保存simditor對象
                toolbar: ['bold', 'italic', 'underline', 'strikethrough',
                    'color', '|', 'ol', 'ul', 'blockquote', 'code', '|',
                    'link', 'image', '|', 'indent', 'outdent'
                ]//自定義工具欄
            }
        },
        ready() {
            this.createEditor()
        },
        methods: {
            createEditor() {
                var _this = this
                this.editor = new Simditor({
                    textarea: $('#' + _this.namess),
                    toolbar: _this.toolbar,
                    upload: {
                        url: apic + '/api/CommAnnex/UploadFiles', //文件上傳的接口地址
//                      params: null, //鍵值對,指定文件上傳接口的額外參數,上傳的時候隨文件一起提交
                        fileKey: 'fileDataFileName', //服務器端獲取文件數據的參數名
                        connectionCount: 3,//同時上傳個數
                        leaveConfirm: '正在上傳文件'
                    },
                    pasteImage: true,//是否允許粘貼上傳圖片,依賴 upload 選項,僅支持 Firefox 和 Chrome 瀏覽器。
                    tabIndent: true,//是否在編輯器中使用 tab 鍵來縮進
                });
                this.editor.on("valuechanged", function(e, src) {
                    _this.value = _this.editor.getValue()
                })//valuechanged是simditor自帶獲取值得方法
            }
        }
    }
    圖片粘貼上傳的地址默認為

 

 需要修改upload.js文件,找到下面代碼

_this.trigger('uploadprogress', [file, file.size, file.size]);  
_this.trigger('uploadsuccess', [file, newresult]); 
return $(document).trigger('uploadsuccess', [file, result, _this]);

修改為以下代碼即可

var newresult = JSON.parse("{\"file_path\":\""+ result.Data[0].FileUrl +"\"}"); //獲取正確地址_this.trigger('uploadprogress', [file, file.size, file.size]);  
_this.trigger('uploadsuccess', [file, newresult]); 
return $(document).trigger('uploadsuccess', [file, newresult, _this]);

  父頁面引用:

  

  <simditor :value.sync='value' v-ref:simditor></simditor>

  如果需要設置富文本框值就使用以下代碼

  this.$refs.simditor.editor.setValue(data.describe)

 大概simditor組件就封裝好了,本人新手純手打如果有什么不好,請各位多多指導。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM