iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >vue中wangEditor5编辑器如何使用
  • 418
分享到

vue中wangEditor5编辑器如何使用

2023-07-05 18:07:09 418人浏览 安东尼
摘要

这篇文章主要介绍了Vue中wangEditor5编辑器如何使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇vue中wangEditor5编辑器如何使用文章都会有所收获,下面我们一起来看看吧。一、wangEdi

这篇文章主要介绍了Vue中wangEditor5编辑器如何使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇vue中wangEditor5编辑器如何使用文章都会有所收获,下面我们一起来看看吧。

    一、wangEditor5是什么

    wangEditor是一款富文本编译器插件,其他的我就不再过多赘述,因为官网上有一大截对于这个编译器的介绍,但我摸索使用的这两天里给我的最直观的感受就是,它是由中国开发者开发,所有的文档都是中文的,这一点上对我这个菜鸡来说非常友好,不用再去逐字逐句翻译,然后去读那些蹩脚的机翻中文。而且功能很丰富,能够满足很多需求,wangEditor5提供很多版本的代码,vue2,vue3React都支持。

    二、wangEditor5基本使用

    (一)、安装

    yarn add @wangeditor/editor-for-vue# 或者 npm install @wangeditor/editor-for-vue --save

    (二)、编译器引入

    import { Editor, Toolbar } from '@wangeditor/editor-for-vue';

    Editor:引入@wangEditor编译器 

    Toolbar:引入菜单栏

    (三)、CSS及变量引入

    <style src="@wangeditor/editor/dist/css/style.css" > </style>

    这里需要注意,引入的样式写在带有scoped标签的style内无效。只能引入在全局样式里,但可能会造成样式覆盖,一般会有个清除样式的文件,会把里面的样式覆盖掉。

    三、wangEditor5工具栏配置

    工具栏配置有很多选项,这里以官方为主,我只做一些常用的配置介绍。

    (一)、editor.getAllMenuKeys() 

    查询编辑器注册的所有菜单 key (可能有的不在工具栏上)这里注意要在

        onCreated(editor) {            this.editor = Object.seal(editor)         },

    这个函数中去调用 (这个函数是基本配置之一),不然好像调不出来,当然也有可能是博主太菜。

    (二)、toolbarConfig中的excludeKeys

    toolbarConfig: {        excludeKeys:["uploadVideo","fullScreen","emotion","insertTable"]       },

    这个是菜单栏配置的一种:排除某项配置 ,这里填写的key值就是用上面那个方法,查出来的key值。

    四、wangEditor5上传图片

    首先在data中return以下信息。

    editorConfig: {         placeholder: '请输入内容...' ,        MENU_CONF: {uploadImage: {customUpload: this.uploadImg,},}      },

    然后书写this.uploadImg函数。

     uploadImg(file, insertFn){      let imgData = new FORMData();imgData.append('file', file);      axiOS({        url: this.uploadConfig.api,        method: 'post',        data: imgData,      }).then((response) => {       insertFn(response.data.FileURL);      });    },

    注意,这里因为返回的数据结构与@wangeditor要求的不一致,因此要使用 insertFn 函数 去包裹返回的url地址。

    五、wangEditor5的一些问题收集及解决

    (一)、引入@wangEditor 编译报错 " Module parse failed: Unexpected token (12828:18)You may need an appropriate loader to handle this file type."

    vue中wangEditor5编辑器如何使用

    解决方法:在 wwebpack.base.conf.js 文件的module>rules>.js 的include下加入

    resolve('node_modules/@wangeditor')

     就可以了。

    vue中wangEditor5编辑器如何使用

    (二)、@wangeditor有序列表无序列表的样式消失问题。

    大概率是全局样式清除导致的样式消失,可以去调试工具里看一看,样式覆盖的问题。

    然后在style里deep一下改变样式就行了。

    .editorStyle{  /deep/ .w-e-text-container>.w-e-scroll>div ol li{    list-style: auto ;  }  /deep/ .w-e-text-container>.w-e-scroll>div ul li{    list-style: disc ;  }  /deep/ .w-e-text-placeholder{    top:7px;  }  }

    六、完整代码

    <template>  <div v-loading="Loading" class="app_detail">    <el-form ref="form" :rules="rules" :model="appDetail" label-width="80px">      <el-form-item prop="name" label="应用名称">        <el-input v-model="appDetail.name" ></el-input>      </el-form-item>      <el-form-item label="分类">        <el-select          v-model="appDetail.appClassificationID"                    placeholder="选择应用分类"        >          <template v-for="item in classes">            <el-option              v-if="item.parentAppClassificationID"              :key="item.appClassificationID"              :label="item.appClassificationName"              :value="item.appClassificationID"            ></el-option>          </template>        </el-select>        <div class="inputdesc">为了适应前台展示,应用只能属于二级分类</div>      </el-form-item>      <el-form-item label="所属组织">        <el-select          v-model="appDetail.orgID"          placeholder="请选择所属组织"                  >          <el-option            v-for="item in myorgs"            :key="item.orgID"            :label="item.name"            :value="item.orgID"          ></el-option>        </el-select>      </el-form-item>      <el-form-item prop="tags" label="标签">        <el-select          v-model="appDetail.tags"          multiple          filterable                    placeholder="请输入或选择应用标签"        >          <el-option            v-for="item in existTags"            :key="item"            :label="item"            :value="item"          ></el-option>        </el-select>      </el-form-item>      <el-row>        <el-col :span="8" class="appsFrom">          <el-form-item            label="应用LoGo"            ref="uploadpic"            class="el-form-item-cen"            prop="logo"          >            <el-upload              class="avatar-uploader"              :action="uploadConfig.api"              :with-credentials="true"              :headers="uploadConfig.headers"              :show-file-list="false"              :on-success="handleAvatarSuccess"              :on-error="handleAvatarError"              :before-upload="beforeAvatarUpload"            >              <img v-if="appDetail.logo" :src="appDetail.logo" class="avatar" />              <i v-else class="el-icon-plus avatar-uploader-icon"></i>              <i                v-if="appDetail.logo"                class="el-icon-delete"                @click.stop="() => handleRemove()"              ></i>            </el-upload>            <span >              建议上传 100*100 比例的Logo            </span>          </el-form-item>        </el-col>      </el-row>      <el-form-item prop="desc" label="应用简介">        <el-input          type="textarea"          v-model="appDetail.desc"          :rows="3"                  ></el-input>      </el-form-item>      <el-form-item prop="introduction" label="应用详情">        <div >        <Toolbar                        :editor="editor"            :defaultConfig="toolbarConfig"            :mode="mode"            class="barStyle"        />        <Editor                        v-model="appDetail.introduction"            :defaultConfig="editorConfig"            :mode="mode"            @onCreated="onCreated"            class="editorStyle"        />    </div>      </el-form-item>    </el-form>    <el-button      class="save_btn"      type="primary"      @click="onSubmit"      :loading="commitLoading"      >保存</el-button    >  </div></template> <script>import { updateApp } from '@/api/app';import { getStoreAvailableTags } from '@/api/appStore';import { getToken } from '@/utils/auth';import axios from 'axios';import { errorHandle } from '../../../../utils/error';import { Editor, Toolbar } from '@wangeditor/editor-for-vue';import { IToolbarConfig, DomEditor, IEditorConfig } from '@wangeditor/editor'export default {  name: 'BasicInfo',  components: { Editor, Toolbar },  props: {    appDetail: {      type: Object    },    marketID: {      type: String    },    Loading: Boolean  },  data() {    var baseDomain = process.env.BASE_API;    if (baseDomain == '/') {      baseDomain = window.location.origin;    }    const isChinese = (temp) => {      return /^[\u4e00-\u9fa5]+$/i.test(temp);    };    const tagValidate = (rule, value, callback) => {      let checked = true;      value.map((tag) => {        if (tag.length < 2) {          callback('每个标签至少两个字符');          checked = false;          return;        }        if (isChinese(tag) && tag.length > 5) {          callback('中文标签字数应处于2-5个之间');          checked = false;          return;        }        if (Number(tag) > 0) {          callback('标签不能为纯数字组成');          checked = false;          return;        }      });      if (checked) {        callback();      }    };    return {      editor: null,      toolbarConfig: {        excludeKeys:["uploadVideo","fullScreen","emotion","insertTable"]       },      editorConfig: {         placeholder: '请输入内容...' ,        MENU_CONF: {uploadImage: {customUpload: this.uploadImg,},}      },      mode: 'default', // or 'simple'      commitLoading: false,      classes: [],      existTags: [],      appPublishTypes: [        {          value: 'public',          label: '免费公开'        },        {          value: 'integral',          label: '金额销售'        },        {          value: 'private',          label: '私有'        },        {          value: 'show',          label: '展览'        }      ],      uploadConfig: {        api: `${baseDomain}/app-server/uploads/picture`,        headers: {          Authorization: getToken()        },      },      editorOption: {},      rules: {        name: [          { required: true, message: '应用名称不能为空', trigger: 'blur' },          { min: 2, message: '至少两个字符', trigger: 'blur' },          { max: 24, message: '应用名称建议不超过24个字符', trigger: 'blur' }        ],        desc: [          { required: true, message: '应用简介不能为空', trigger: 'blur' },          { min: 10, message: '至少10个字符', trigger: 'blur' },          { max: 82, message: '描述最多82个字符', trigger: 'blur' }        ],        introduction: [          { max: 10140, message: '描述最多10240个字符', trigger: 'blur' }        ],        tags: [{ validator: tagValidate, trigger: 'change' }]      }    };  },  created() {    this.fetchStoreAppClassList();    this.fetchStoreAppTags();  },  computed: {    myorgs() {      return this.$store.state.user.userOrgs;    }  },    methods: {    uploadImg(file, insertFn){      let imgData = new FormData();imgData.append('file', file);      axios({        url: this.uploadConfig.api,        method: 'post',        data: imgData,      }).then((response) => {       insertFn(response.data.FileURL);      });    },    onCreated(editor) {            this.editor = Object.seal(editor)         },    fetchStoreAppTags() {      getStoreAvailableTags({        marketID: this.marketID,        size: -1      })        .then((res) => {          if (res && res.tags) {            const tags = [];            res.tags.map((item) => {              tags.push(item.name);            });            this.existTags = tags;          }        })        .catch((err) => {          this.Loading = false;        });    },    fetchStoreAppClassList() {      this.$store        .dispatch('GetStoreAppClassificationList', {          marketID: this.marketID,          disableTree: true        })        .then((res) => {          if (res) {            this.classes = res;          }        })        .catch(() => {});    },    fetchUserOrgs() {      this.$store        .dispatch('GetUserOrgList')        .then((res) => {          if (res) {            this.myorgs = res;          }        })        .catch(() => {});    },    markdownContentUpdate(md, render) {      this.appData.introduction_html = render;    },    markdownImgAdd(pos, $file) {      // 第一步.将图片上传到服务器.      var formdata = new FormData();      formdata.append('file', $file);      axios({        url: this.api,        method: 'post',        data: formdata,        headers: this.Token      }).then((re) => {        if (re && re.data && re.data.data) {          this.$refs.md.$img2Url(pos, re.data.data);        }      });    },    handleAvatarSuccess(res, file) {      this.appDetail.logo = res.FileURL;    },    handleAvatarError(re) {      if (re.code == 10024) {        this.$message.warning(          '上传图片类型不支持,请上传以.png .jpg .jpeg 结尾的图片'        );        return;      }      this.$message.warning('上传失败!');    },    beforeAvatarUpload(file) {      const isJPG = file.type === 'image/jpeg';      const isPng = file.type === 'image/png';      const isLt2M = file.size / 1024 / 1024 < 2;       if (!isJPG && !isPng) {        this.$message.warning('上传Logo图片只能是JPG、PNG格式!');      }      if (!isLt2M) {        this.$message.warning('上传头像图片大小不能超过 2MB!');      }      return (isJPG || isPng) && isLt2M;    },    handleRemove() {      this.$confirm('是否删除logo', '提示', {        confirmButtonText: '确定',        cancelButtonText: '取消',        type: 'warning'      }).then(() => {        this.appDetail.logo = '';      });    },    handlePictureCardPreview(file) {      this.dialogImageUrl = file.url;      this.dialogVisible = true;    },    changeSelectApp_type_id(value) {      this.appData.app_type_id = value;      this.$forceUpdate();    },    changeSelectPublish_type(value) {      this.appData.publish_type = value;      this.$forceUpdate();    },    onSubmit() {      this.$refs.form.validate((valid) => {        if (valid) {          this.commitLoading = true;          this.$confirm('是否提交数据', '提示', {            confirmButtonText: '确定',            cancelButtonText: '取消',            type: 'warning'          })            .then(() => {              updateApp(this.appDetail)                .then((res) => {                  this.$message.success('应用信息更新成功');                  this.commitLoading = false;                })                .catch((err) => {                  errorHandle(err);                  this.commitLoading = false;                });            })            .catch(() => {              this.commitLoading = false;            });        } else {          return false;        }      });    }  }};</script><style lang="scss" scoped >.app_detail {  position: relative;  padding-bottom: 20px;  .save_btn {    margin-left: 80px;      }  .el-select {    width: 100%;  }}.editorStyle{  /deep/ .w-e-text-container>.w-e-scroll>div ol li{    list-style: auto ;  }  /deep/ .w-e-text-container>.w-e-scroll>div ul li{    list-style: disc ;  }  /deep/ .w-e-text-placeholder{    top:7px;  }  }.barStyle{  /deep/ .w-e-bar-item{    padding:2.5px  }    /deep/ .w-e-bar-item > button >.title{    border-left:0 !important;  }}</style><style src="@wangeditor/editor/dist/css/style.css" >.inputdesc {  font-size: 12px;  color: rgba(0, 0, 0, 0.45);  transition: color 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);}.app_detail img {  width: auto;}.app_detail .ql-formats {  line-height: 22px;}</style>

    关于“vue中wangEditor5编辑器如何使用”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“vue中wangEditor5编辑器如何使用”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注编程网精选频道。

    --结束END--

    本文标题: vue中wangEditor5编辑器如何使用

    本文链接: https://www.lsjlt.com/news/354701.html(转载时请注明来源链接)

    有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

    本篇文章演示代码以及资料文档资料下载

    下载Word文档到电脑,方便收藏和打印~

    下载Word文档
    猜你喜欢
    • vue中wangEditor5编辑器如何使用
      这篇文章主要介绍了vue中wangEditor5编辑器如何使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇vue中wangEditor5编辑器如何使用文章都会有所收获,下面我们一起来看看吧。一、wangEdi...
      99+
      2023-07-05
    • Vue中如何使用tiptap富文本编辑器
      Vue中如何使用tiptap富文本编辑器,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。为什么使用tiptap?市面上有不少富文...
      99+
      2024-04-02
    • Linux 中如何使用Vi编辑器
      本篇文章给大家分享的是有关Linux 中如何使用Vi编辑器,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。一、centOS下vi高亮显示 首先,vim才有语法高亮的功能,配置文件...
      99+
      2023-06-13
    • CentOS中如何使用vi编辑器
      这期内容当中小编将会给大家带来有关CentOS中如何使用vi编辑器,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。vi的基本概念 基本上vi可以分为三种状态,分别是命令模式(command mod...
      99+
      2023-06-10
    • VUE3中如何使用JSON编辑器
      这篇文章主要讲解了“VUE3中如何使用JSON编辑器”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“VUE3中如何使用JSON编辑器”吧!1、先看看效果图,可以自行选择展示效果2、这是我在vu...
      99+
      2023-07-06
    • 如何使用vi编辑器
      本篇内容主要讲解“如何使用vi编辑器”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何使用vi编辑器”吧!vi有命令模式和插入模式之分。vi启动后就处于命令模式。在命令模式下,可以随意移动光标、...
      99+
      2023-06-10
    • vue-json-editorjson编辑器的使用
      目录一、概述二、vue-json-editor 使用安装插件使用访问三、bin-code-editor安装模块引入一、概述 现有一个vue项目,需要一个json编辑器,能够...
      99+
      2024-04-02
    • 如何使用Mu编辑器Python
      本篇内容主要讲解“如何使用Mu编辑器Python”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何使用Mu编辑器Python”吧!开始使用 Python 的 turtle 模块在 Linux 或...
      99+
      2023-06-16
    • wps宏编辑器如何使用
      这篇文章主要讲解了“wps宏编辑器如何使用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“wps宏编辑器如何使用”吧!首先打开wps,进入表格,点击上方“开发工具”打开后,点击下面的“js宏”...
      99+
      2023-07-02
    • markdown编辑器tui.editor如何使用
      这篇文章主要介绍“markdown编辑器tui.editor如何使用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“markdown编辑器tui.editor如何使用”文章能帮助大家解决问题。安装使用...
      99+
      2023-07-05
    • linux中如何使用Sed文本编辑器
      这篇文章给大家分享的是有关linux中如何使用Sed文本编辑器的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。Sed 缺少通常的文本框,而是按照用户的命令直接写入到文件上。sed 命令是为 AT&...
      99+
      2023-06-15
    • vue中如何使用codemirror插件实现代码编辑器功能
      这篇文章主要介绍“vue中如何使用codemirror插件实现代码编辑器功能”,在日常操作中,相信很多人在vue中如何使用codemirror插件实现代码编辑器功能问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答...
      99+
      2023-06-20
    • Vue如何整合mavon-editor编辑器(markdown编辑和预览)
      目录简介说明官网网址使用编辑功能代码使用预览功能结果展示简介 说明 本文介绍Vue如何使用markdown编辑器。 mavon-editor是目前比较主流的markdown编辑器,本...
      99+
      2022-11-13
      Vue整合mavon-editor编辑器 Vue markdown编辑
    • 先进SlickEdit编辑器如何使用
      这期内容当中小编将会给大家带来有关先进SlickEdit编辑器如何使用,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。SlickEdit 作为一个高效的.NET程序语言。其混合了函数语言和物件导向程序编制语...
      99+
      2023-06-17
    • linux如何使用Vi/Vim编辑器
      这篇文章主要为大家展示了“linux如何使用Vi/Vim编辑器”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“linux如何使用Vi/Vim编辑器”这篇文章吧。VI 编辑器是一个基于命令行的、功能...
      99+
      2023-06-16
    • Vue.js中如何使用Ueditor富文本编辑器
      这篇文章将为大家详细讲解有关Vue.js中如何使用Ueditor富文本编辑器,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。1. 总体思路1.1 模块化vue...
      99+
      2024-04-02
    • 如何使用vue codemirror插件实现代码编辑器功能
      本篇内容主要讲解“如何使用vue codemirror插件实现代码编辑器功能”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何使用vue codemirror插件实现代码编辑器功能”吧!1、使用...
      99+
      2023-07-04
    • 如何使用Java编辑器控件RSyntaxTextArea
      本篇文章给大家分享的是有关如何使用Java编辑器控件RSyntaxTextArea ,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。RSyntaxTextArea 是一个支持语法...
      99+
      2023-06-17
    • 如何在在Vue3中使用markdown 编辑器组件
      目录安装引入组件基础用法保存后的 markdown 或者 html 文本如何渲染在页面上?安装 # 使用 npm npm i @kangc/v-md-editor@next -S...
      99+
      2024-04-02
    • 如何正确的使用Vi编辑器
      如何正确的使用Vi编辑器?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。vi的基本概念  基本上vi可以分为三种状态,分别是命令模式(command mode)、插入模式(I...
      99+
      2023-06-10
    软考高级职称资格查询
    编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
    • 官方手机版

    • 微信公众号

    • 商务合作