vue结合el-upload与el-input实现自制简易富文本编辑器,支持上传图片,需要有个接口把本地图片转成在线链接

13 篇文章 0 订阅
10 篇文章 2 订阅

vue页面点击修改页面循环渲染元素中的数据的值不生效,我的建议是双管齐下

 gotoEdit(i) {
      this.$set(this.reportList[i], "editStatus", true);
      this.$forceUpdate();
    },

vue结合el-upload与el-input实现自制简易富文本编辑器,支持上传图片,需要有个接口把本地图片转成在线链接

展示 

编辑

  <template v-if="pageStatus !== 'see'">
                  <span
                    v-if="item.editStatus"
                    @click="
                      (item.editStatus = false),
                        setDetailOrAdd('dontCloseWindow')
                    "
                    title="确定"
                    class="buttonStyle over"
                  ></span
                  ><span
                    v-else
                    @click="gotoEdit(i)"
                    title="编辑"
                    class="buttonStyle edit"
                  ></span> </template
                >
              </div>
              <el-input
                class="main-part"
                v-if="item.editStatus"
                v-model="item.propertyValue"
                placeholder="请输入内容"
                style="width: 100%;height: 300px;"
                type="textarea"
                show-word-limit
              ></el-input>
              <div v-else class="main-part" v-html="item.propertyValue"></div>
              <!-- <div
              v-if="item.editStatus"

              class="main-part"
              :contenteditable="pageStatus !== 'see' ? true : false"
              v-html="item.propertyValue"
            ></div> -->

              <div v-if="item.editStatus" class="add-button">
                <el-upload
                  class="upload"
                  action="/cbrc/file/upload"
                  :on-success="
                    (response, file, fileList) =>
                      upsuccessImg(response, file, fileList, i)
                  "
                  :headers="header"
                  :show-file-list="false"
                  :on-remove="deletefileImg"
                  :before-upload="handleChangeImg"
                  :file-list="imgList"
                  ref="uploadImg"
                >
                  <el-button type="primary" class="blue"
                    >添加图片<i class="el-icon-upload el-icon--right"></i
                  ></el-button>
                </el-upload>
              </div>
 gotoEdit(i) {
      this.$set(this.reportList[i], "editStatus", true);
      this.$forceUpdate();
    },
    upsuccessImg(response, file, fileList, index) {
      if (response.code == 200) {
        this.attachmentLists = fileList;
        if (this.attachmentLists && this.attachmentLists[0].response) {
          this.attachmentLists[0].response.data.forEach(item => {
            this.imgList.push({
              name: item.attachName,
              url: item.attachPath
            });
            // 上传成功就拼接成富文本
            const setOver =
              this.reportList[index].propertyValue +
              ('<br /><img src="/cbrc' + item.attachPath + '" ><br />');
            this.$set(this.reportList[index], "propertyValue", setOver);

          });
        }
 this.imgList=[];
      } else {
        this.$message.error("图片添加失败");
      }
    },
    //附件删除
    deletefileImg(file, fileList) {
      var url = "";
      if (file.url) {
        url = file.url;
      } else {
        url = file.response.data[0].attachPath;
      }
      this.$http({
        method: "GET",
        url: "/cbrc/file/del?filePath=" + url
      }).then(res => {
        if (res) {
          this.fileList = [];
          this.fileName = "";
          this.attachmentLists = fileList;
          this.$message.success("删除成功");
        }
      });
    },
    handleChangeImg(file, fileList) {
      var size = file.size / 1024 / 1024;
      if (size > 10) {
        this.$message.warning("上传文件大小不能大于10M");
        return false;
      }
    },

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JianZhen✓

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值