Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同一个页面创建多个编辑器,自定义按钮只会在最后一个编辑器创建。 #178

Closed
LiuXIn011 opened this issue Dec 5, 2023 · 1 comment

Comments

@LiuXIn011
Copy link

image

代码:

<template>
  <div>
    <vue-ueditor-wrap
    v-model="msg"
    editor-id="custom-btn-demo-01"
    :config="editorConfig"
    @before-init="addCustomButton"
  ></vue-ueditor-wrap>
  <vue-ueditor-wrap
    v-model="msg"
    :config="editorConfig"
    editor-id="custom-btn-demo-02"
    @before-init="addCustomButton"
  ></vue-ueditor-wrap>
  </div>
</template>

<script>
import VueUeditorWrap from 'vue-ueditor-wrap'
export default {
  components: {
    VueUeditorWrap
  },
  data() {
    return {
      msg: '',
      editorConfig:{}
    };
  },
  created() {
    // 这里根据你项目的具体情况设置,我这么设置是针对这个文档网站的
    this.UEDITOR_HOME_URL = '/UEditor/';
    this.editorConfig = {
      UEDITOR_HOME_URL: this.UEDITOR_HOME_URL,
      listiconpath: `${this.UEDITOR_HOME_URL}listicon/`,
    };
    
  },
  methods: {
    addCustomButton(editorId) {
      window.UE.registerUI(
        'simpleupload',
        (editor, uiName) => {
          // 创建一个 button
          const btn = new window.UE.ui.Button({
            // 按钮的名字
            name: uiName,
            // 提示
            title: '鼠标悬停时的提示文字',
            // 需要添加的额外样式,可指定 icon 图标
            cssRules: '',
            // 点击时执行的命令
            onclick() {
              // 这里可以不用执行命令,做你自己的操作也可
              console.log(13);
            },
          })
          // 因为你是添加 button,所以需要返回这个 button
          return btn;
        },
        undefined /* 指定添加到工具栏上的哪个位置,默认时追加到最后 */,
        editorId /* 指定这个 UI 是哪个编辑器实例上的,默认是页面上所有的编辑器都会添加这个按钮 */
      );
    },
  },
};
</script>
@LiuXIn011
Copy link
Author

按钮名称重复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant