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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • linux 通配符

    linux 通配符*–代表所有字符?-通配符,代表一个字符,一个?代表只匹配一个字符????4个?代表匹配4个字符;分号两个命令之间的分隔符#文件里面的注释|管道~用户家目录-上一次目

  • 从硬盘上安装Fedora12

    从硬盘上安装Fedora12一、引言Fedora12的liveCD:Fedora-12-i686-Live.iso,至今未硬盘安装成功。在引导过程中,报此类错误:[drm:drm_mode_rmfb]triedtoremoveafbthatwedidntown无奈之下,只好下载Fedora12的DVD版:Fedora12-i386-DVD.iso文件比较大,2G多一些。

  • sm4加密和sm3加密

    sm4加密和sm3加密sm4加密有32位key值加密和16位key值加密加粗样式sm4中32位加密:可以参考:https://www.npmjs.com/package/@haici/gmsm4sm4中16位加密:可以参考:https://blog.csdn.net/qq_34574204/article/details/107961807?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162501640416780366595087%2522%252C%

  • sigaction介绍

    sigaction介绍sigaction原型:intsigaction(intsigno,conststructsigaction*restrictact,structsigaction*restrictoact);@signo信号编号@act要注册的信号动作@oact原信号动作

  • 大学学姐给学弟学妹们的寄语_怎么去大厂工作

    大学学姐给学弟学妹们的寄语_怎么去大厂工作很多小伙伴问我进大厂到底需要怎样的技术能力,经过几天的思考和总结,终于梳理出一份相对比较完整的技能清单,太顶了,建议收藏!!

  • Android Fragment 简单实例

    Android Fragment 简单实例

发表回复

您的电子邮箱地址不会被公开。

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