elementUi+vue+php 引入wangeditor
in 前端 with 0 comment

elementUi+vue+php 引入wangeditor

in 前端 with 0 comment

后端实现

public function image(Request $request)
{
    $files = $request->file();
    $paths = [];
    array_map(function ($file) use (&$paths){
        $path = Storage::putFile('upload', $file);
        $paths[] = env('APP_URL') . "storage/app/$path";
            $bashPaths[] = storage_path('app/') . $path;
        }, $files);
        $path = Arr::first($paths);

        return $this->success(compact('path'));
    }
}

前端实现

<template>
  <div>
    <div ref="editorElem"></div>
  </div>
</template>

import E from "wangeditor";
export default {

  data() {
    return {
      editor: null,
      api: null
    };
  },

  methods: {
    // 插入html
    toHtml(videoUrl) {
      this.editor.txt.append(`<iframe src=${videoUrl}></iframe>`);
    },
    
    // 设置文本
    setHtml(html) {
      this.editor.txt.html(html);
    },
  },
  
  mounted() {
    let that = this;
    this.api = "api/upload/image";
    this.editor = new E(this.$refs.editorElem);
    this.editor.customConfig.uploadImgServer = this.api
    this.editor.customConfig.uploadImgHooks = {
        customInsert: function (insertImg, result, editor) {
            var url = result.data.path
            insertImg(url)
        }
    }
    this.editor.customConfig.onchange = html => {
      this.$emit("updateTitle", html);
    };
    this.editor.create();
    this.editor.txt.html(this.title);
  },

  watch: {
    dialogFormVisible() {
      this.editor.txt.html(this.title);
      this.$refs.qiniuUpload.init()
    }
  }
赣ICP备17004055号-2