宅男在线永久免费观看网直播,亚洲欧洲日产国码无码久久99,野花社区在线观看视频,亚洲人交乣女bbw,一本一本久久a久久精品综合不卡

全部
常見問題
產(chǎn)品動態(tài)
精選推薦

WangEditor編輯器 復(fù)制粘貼方式上傳圖片

管理 管理 編輯 刪除

2f088202302161426598747.jpg

本文章向大家介紹WangEditor 提交base64格式圖片上傳至服務(wù)器,主要包括WangEditor 提交base64格式圖片上傳至服務(wù)器使用實例、應(yīng)用技巧、基本知識點總結(jié)和需要注意事項,具有一定的參考價值,需要的朋友可以參考一下。

1. wangEditor官網(wǎng)

2.引入安裝

友情提示:多商戶,PRO,多店版,陀螺匠的項目找到wangEditor的組件參考修改可直接使用。
// 安裝
npm i wangeditor --save

// 使用
import E from "wangeditor"
this.editor = new E(this.$refs['wang-editor']);

3.使用

定義上傳圖片,先轉(zhuǎn)base64,轉(zhuǎn)blob,上傳服務(wù)器
mounted() {
    this.createEditor();
},
methods: {
  createEditor() {
      let _this = this;
      const menuKey = 'alertMenuKey';
      const html = 'alertHtml';
      this.editor = new E(this.$refs['wang-editor']);

      this.editor.menus.extend(menuKey, AlertMenu);
      this.editor.menus.extend(html, HtmlMenu);
      this.editor.config.menus = this.editor.config.menus.concat(html);
      this.editor.config.menus = this.editor.config.menus.concat(menuKey);
      this.editor.config.uploadImgFromMedia = function () {
        _this.getimg();
      };
      // this.editor.config.uploadVideoHeaders = _this.header;
      this.editor.config.height = 600;
      this.editor.config.menus = [
        'alertHtml',
        'head',
        'bold',
        'fontSize',
        'fontName',
        'italic',
        'underline',
        'strikeThrough',
        'indent',
        'lineHeight',
        'foreColor',
        'backColor',
        'link',
        'list',
        // "todo",
        'justify',
        'quote',
        'image',
        'alertMenuKey',
        // "table",
        'code',
        'splitLine',
      ];
      this.editor.config.customUploadImg = function (files, insert) {
        // 上傳代碼返回結(jié)果之后,將圖片插入到編輯器中
        _this.filesToBase64(files);
      };
      // 配置全屏功能按鈕是否展示
      //   this.editor.config.showFullScreen = false
      this.editor.config.uploadImgShowBase64 = true;
      //   this.editor.config.uploadImgAccept = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp']
      this.editor.config.zIndex = 0;
      //   this.editor.config.uploadImgMaxSize = this.uploadSize * 1024 * 1024
      this.editor.config.compatibleMode = () => {
        // 返回 true 表示使用兼容模式;返回 false 使用標(biāo)準(zhǔn)模式
        return true;
      };
      this.editor.config.onchange = (newHtml) => {
        this.newHtml = newHtml;
        this.$emit('editorContent', newHtml);
      };
      this.editor.config.onchangeTimeout = 300; // change后多久更新數(shù)據(jù)

      this.editor.create();
    },
    filesToBase64(files) {
      let _this = this;
      files.map((item) => {
        var reader = new FileReader();
        reader.onload = function (event) {
          var base64_str = event.target.result;
          //div中的img標(biāo)簽src屬性賦值,可以直接展示圖片
          var bytes = window.atob(base64_str.split(',')[1]);
          var array = [];
          for (let i = 0; i < bytes.length; i++) {
            array.push(bytes.charCodeAt(i));
          }
          var blob = new Blob([new Uint8Array(array)], { type: 'image/jpeg' });
          var formData = new FormData();
          formData.append('file', blob, Date.now() + '.jpg');
          formData.append('filename', 'file');
          fetch('http://xxx.xxx.xxx/upload/image/0/file', {
            method: 'post',
            headers: {
              'X-Token':localStorage.getItem('token'),//token的key和value值根據(jù)自己項目進(jìn)行修改
            },
            body: formData,
          })
            .then((response) => response.json())
            .then((res) => {
              console.log(res.data);
              _this.editor.cmd.do('insertHTML', ``);
              //模板字符串拼接的圖片路徑層級也根據(jù)自己項目返回內(nèi)容進(jìn)行調(diào)整
            });
        };
        // 傳入一個參數(shù)對象即可得到基于該參數(shù)對象的文本內(nèi)容
        reader.readAsDataURL(item);
      });
    },
},


附件

index.vue.zip

請登錄后查看

徐斗明 最后編輯于2023-09-13 16:55:28

快捷回復(fù)
回復(fù)
回復(fù)
回復(fù)({{post_count}}) {{!is_user ? '我的回復(fù)' :'全部回復(fù)'}}
排序 默認(rèn)正序 回復(fù)倒序 點贊倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level || item.bbs_level }}

作者 管理員 企業(yè)

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
{{item.is_suggest == 1? '取消推薦': '推薦'}}
沙發(fā) 板凳 地板 {{item.floor}}#
{{item.user_info.title || '暫無簡介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打賞
已打賞¥{{item.reward_price}}
{{item.like_count}}
{{item.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回復(fù) {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打賞
已打賞¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)
查看更多
打賞
已打賞¥{{reward_price}}
11005
{{like_count}}
{{collect_count}}
添加回復(fù) ({{post_count}})

相關(guān)推薦

快速安全登錄

使用微信掃碼登錄
{{item.label}} 加精
{{item.label}} {{item.label}} 板塊推薦 常見問題 產(chǎn)品動態(tài) 精選推薦 首頁頭條 首頁動態(tài) 首頁推薦
取 消 確 定
回復(fù)
回復(fù)
問題:
問題自動獲取的帖子內(nèi)容,不準(zhǔn)確時需要手動修改. [獲取答案]
答案:
提交
bug 需求 取 消 確 定
打賞金額
當(dāng)前余額:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
請輸入 0.1-{{reward_max_price}} 范圍內(nèi)的數(shù)值
打賞成功
¥{{price}}
完成 確認(rèn)打賞

微信登錄/注冊

切換手機(jī)號登錄

{{ bind_phone ? '綁定手機(jī)' : '手機(jī)登錄'}}

{{codeText}}
切換微信登錄/注冊
暫不綁定
CRMEB客服

CRMEB咨詢熱線 咨詢熱線

400-8888-794

微信掃碼咨詢

CRMEB開源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
返回頂部 返回頂部
CRMEB客服