vue 富文本编辑框_基于vue的富文本编辑器

vue 富文本编辑框_基于vue的富文本编辑器1、下载插件npmiwangeditor–save插件官网地址:https://www.wangeditor.com/2、封装富文本组件<templatelang=”html”><divclass=”editor”><!–<divref=”toolbar”class=”toolbar”></div>–><divref=”editor”class=”text”></div

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

1、下载插件

npm i wangeditor –save
插件官网地址:https://www.wangeditor.com/

2、封装富文本组件

<template lang="html">
  <div class="editor">
    <!-- <div ref="toolbar" class="toolbar"></div> -->
    <div ref="editor" class="text"></div>
  </div>
</template>

<script>
  import E from 'wangeditor'
  export default {
    name: 'editoritem',
    data() {
      return {
        // uploadPath,
        editor: null,
        info_: null
      }
    },
    model: {
      prop: 'value',
      event: 'change'
    },
    props: {
      value: {
        type: String,
        default: ''
      },
      isClear: {
        type: Boolean,
        default: false
      }
    },
    watch: {
      isClear(val) {
        // 触发清除文本域内容
        if (val) {
          this.editor.txt.clear()
          this.info_ = null
        }
      },
      value: function(value) {
        if (value !== this.editor.txt.html()) {
          this.editor.txt.html(this.value)
        }
      }
      //value为编辑框输入的内容,这里我监听了一下值,当父组件调用得时候,如果给value赋值了,子组件将会显示父组件赋给的值
    },
    mounted() {
      this.seteditor()
    },
    beforeDestroy() {
      // 调用销毁 API 对当前编辑器实例进行销毁
      this.editor.destroy()
      this.editor = null
    },
    methods: {
      seteditor() {
        this.editor = new E( this.$refs.editor)
        // this.editor.customConfig = this.editor.customConfig ? this.editor.customConfig : this.editor.config;
        // 配置 server 上传图片接口地址
        // this.editor.config.uploadImgServer = '/upload-img'
        this.editor.config.onchange = (html) => {
          this.info_ = html // 绑定当前值
          this.$emit('change', this.info_) // 将内容同步到父组件中
        }


        // 自定义 alert
        this.editor.config.customAlert = function (s, t) {
          switch (t) {
            case 'success':
              this.$Message.success(s)
              break
            case 'info':
              this.$Message.info(s)
              break
            case 'warning':
              this.$Message.warning(s)
              break
            case 'error':
              this.$Message.error(s)
              break
            default:
              this.$Message.info(s)
              break
          }
        }
        // 配置全屏功能按钮是否展示
       this.editor.config.showFullScreen = false

        // 创建富文本编辑器
        this.editor.create()
        this.editor.txt.html(this.value) // 重新设置编辑器内容
      }
    }
  }
</script>
<style lang="scss">
  .editor {
    width: 100%;
    margin: 0 auto;
    position: relative;
    z-index: 0;
  }
  .toolbar {
    border: 1px solid #ccc;
  }
  .text {
    border: 1px solid #ccc;
     min-height: 200px;
    .w-e-text-container{
      height: 200px!important;
    }
    .w-e-text{
      min-height: 200px;
    }
  }
</style>

3、使用组件

<template>
  <div>
    <wangEnduit
      v-model="Content"
      :isClear="isClear"
      @change="change"
      :value="Content"
    />
  </div>
</template>

<script>
export default {
  components: {
    wangEnduit: () => import('@/components/wangEnduit/index'),
  },
  data(){
    return{
      Content:"",
      isClear: false,
    }
  },
  methods:{
      change(val) {
      console.log('val',val)
    },
  }
}
</script>

<style>

</style>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/184117.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • ue4在c盘的缓存_怎么清除ps在C盘的缓存

    ue4在c盘的缓存_怎么清除ps在C盘的缓存大家好,可能很多新手使用UE4的时候会发现C盘越来越小了,那是因为UE4引擎的缓存文件默认保存在C盘的缘故。下面来告诉大家怎么解决这个问题。概述一、出现的问题:UE4的缓存文件会导致C盘膨胀!二、解决的方式:请严格按照下列步骤来执行1.更改UE4的缓存路径2.删除UE4在C盘的缓存3.删除各个引擎版本SwarmAgent(联机构建)的缓存文件…

    2022年10月5日
    3
  • burpsuite简单抓包教程[通俗易懂]

    burpsuite简单抓包教程[通俗易懂]一.配置浏览器(以火狐为例)1.打开菜单,找到选项,点击翻到最下面点击设置,将配置的代理服务器改为手动代理配置,HTTP代理设为127.0.0.1,端口设置为8080(为了burpsuite能截到浏览器发送出来的请求),点击确定。二.burpsuite的设置点击proxy选择Options观察图中的IP地址及端口,如果不是127.0.0.1:8080,则点击add,添加端口和IP地…

    2022年6月14日
    125
  • 统计xml文件中标记框的特性

    统计xml文件中标记框的特性

    2020年11月8日
    187
  • Android11 无Root 访问data目录实现、Android11访问data目录、Android11解除data目录限制、Android11 data空白解决

    Android11 无Root 访问data目录实现、Android11访问data目录、Android11解除data目录限制、Android11 data空白解决Android11无Root访问data目录实现、Android11访问data目录、Android11解除data目录限制、Android11data空白解决、SAF文件访问框架

    2022年7月12日
    40
  • Android json字符串转Map

    Android json字符串转Map今天,同事问我json的问题。遍历json数组,解决完以后。我想到了json转Map这个问题。写一下,发现效果还行那个发上来看看吧。如果想省事的话,用阿里的FastJson我感觉也是不错的,网上教程很多,我就不多说了。注意这是Android自带的json包importorg.json.JSONArray;importorg.json.JSONException;importo…

    2022年6月21日
    228
  • ExpandableListView实例

    ExpandableListView实例先来看效果图:demo中有三个groupitem和多个childitem,groupitem包括一个指示器,一个标题和一个按钮。childitem包括一个图片,一个标题和一个按钮。先来实现布局文件1activity_main.xml

    2022年6月29日
    28

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号