在Vue项目中使用kindEditor编译器

本文介绍如何在项目中使用KindEditor富文本编辑器,包括配置、按钮功能实现及前后端交互等关键技术点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

kingEditor官网地址:http://kindeditor.net/demo.php
里面有大量的demo,可根据需求自行选择。
我在项目中选用kindEditor是因为它的体积比较小(2M多)。(Ueditor编译器7M多)
在项目中写入:

html

<textarea id="content2" name="content" style="width:700px;height:350px;visibility:hidden;" onkeyup="this.value=this.value.replace(/^\s+|\s+$/g,'')">
</textarea>;

js:

function htmlencode(s){
       var div = document.createElement('div');
       div.appendChild(document.createTextNode(s));
       return div.innerHTML;
}
KindEditor.ready(function(K) {
    editor = K.create('#content2', {
           themeType : 'simple',
           afterBlur:function(){
                this.sync();
           }
     });
     //提交按钮
     K('button[name=getHtml]').click(function(e) {
           html_t = editor.html();
           html_k = htmlencode(html_t);
     });
     //清空按钮
     K('button[name=clear]').click(function(e) {
          editor.html('');
          vm_write.cancelSend();
          window.history.go(-1);
     });
});
//在提交编辑器里的内容的时候,需要将html_k转码一下,
html_k = encodeURIComponent(html_k);
axios({
        method:'post',
        url:'/f/api/socialWorkerBridge/add',
        data:{
              type:vm.type,
              title:vm.title,
              content:html_k,
              name:vm.name,
              phone:vm.telphone,
              email:vm.email
          }
     }).then(function(res){
         console.log(res.data);
     }).catch(function (res) {
         console.log(res.data);
     });

在拿到上边所传的html_t的时候,同样需要转码才可以变成我们之前所输入的文字。

vm.content = decodeURIComponent(response.data.content);

以上为个人使用方式,如有错误,望指点。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值