vuejs-如何将自定义图标添加到Quill(撤消/重做)

时间:2019-03-15 03:50:45

标签: javascript vue.js vuejs2 quill

所以我可以用Vue实现按钮功能,但是我似乎无法更改其图标(目前什么也没有)。我该如何解决?

https://codesandbox.io/s/8lnz3r2n12

<template>
  <div id="app">
    <div>Quill editor</div>
    <div ref="editor"></div>
  </div>
</template>

<script>
import "quill/dist/quill.bubble.css";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import undo_icon from "quill/assets/icons/undo.svg";
import redo_icon from "quill/assets/icons/redo.svg";
import Quill from "quill";

export default {
  name: "App",
  components: {},
  data() {
    let self = this;
    return {
      toolbar_settings: {
        container: [
          ["bold", "italic"],
          [
            {
              undo: undo_icon
            },
            {
              redo: redo_icon
            }
          ]
        ],
        handlers: {
          redo() {
            self.editor.history.redo();
          },
          undo() {
            self.editor.history.undo();
          }
        }
      }
    };
  },
  mounted() {
    const self = this;
    let options = {
      debug: this.debug,
      modules: {
        history: {
          delay: 1000,
          maxStack: 100,
          userOnly: false
        },
        toolbar: this.toolbar_settings
        // this.toolbar,
      },
      placeholder: "placeholder",
      readOnly: false,
      theme: "snow"
    };

    this.editor = new Quill(this.$refs.editor, options);
  }
};
</script>

<style>
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

1 个答案:

答案 0 :(得分:1)

只需在定义选项之前添加这三行即可。

var icons = Quill.import("ui/icons");
icons["undo"] = undo_icon;
icons["redo"] = redo_icon;

codepen-https://codesandbox.io/s/m34vk57j3x