首页 > 解决方案 > 如何让 Redactor 所见即所得与 vue.js 一起工作(没有 jQuery)

问题描述

根据网站 ( https://imperavi.com/redactor/ ),当前版本的 redactor 是免费的 jquery。(引自页面“jQuery Free 没有依赖,没有问题”。

我可以让编辑器进入 vue.js,但我不确定如何通过事件绑定数据(因为它没有出现,您可以直接绑定)。

从https://imperavi.com/redactor/docs/callbacks/source/获取想法

我已经尝试过我页面的脚本部分)

window.onload = function () {
  window.Redactor('#redactor1', {
    callbacks: {
      source: {
        changed: function (html) {
          alert('aa')
          return html
        }
      },
      syncBefore: function (html) {
        alert('bb')
        return html
      }
    }
  })
  alert("It's loaded!")
}

但它似乎并没有触发事件 - 除了 alert("it's loaded") 工作正常。也没有错误。

任何想法我做错了什么?

标签: node.jsvuejs2redactorredactor.js

解决方案


You can use inspiration from their Vue plugin: https://github.com/imperavi/vue-redactor

watch: {
    value(newValue, oldValue)
    {
        if (!this.redactor.editor.isFocus()) this.redactor.source.setCode(newValue)
    }
},

推荐阅读