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

无法自定义wangEditor 的颜色 #3882

Closed
Flower-And-You opened this issue Feb 13, 2022 · 8 comments
Closed

无法自定义wangEditor 的颜色 #3882

Flower-And-You opened this issue Feb 13, 2022 · 8 comments
Labels

Comments

@Flower-And-You
Copy link

问题描述

我想要修改wangEditor 的颜色(包括背景颜色与字体颜色),根据文档的指引操作,但无法生效。安装wangEditor 是使用的CDN方式

wangEditor 版本

wangEditor V4与wangEditor V5

是否查阅了文档 ?

(文档链接 www.wangeditor.com/doc

最小成本的复现步骤

(请告诉我们,如何最快的复现该问题?)

  • wangEditor V4

  • 使用CDN方式进行最小的安装,尝试修改颜色
    屏幕截图 2022-02-13 205126
    屏幕截图 2022-02-13 205204
    屏幕截图 2022-02-13 205833

  • wangEditor V5

  • 使用CDN方式进行进行最小的安装,尝试修改颜色
    屏幕截图 2022-02-13 211137
    屏幕截图 2022-02-13 211202

@wangfupeng1988
Copy link
Collaborator

V4 你要把颜色菜单加入到 editor.config.menus = [...] 这个配置中。而你只配置了颜色,但菜单却隐藏了。

V5 你的代码看起来没问题。你可以参考 http://106.12.198.214:8882/main/examples/menu.html 我的 demo ,里面也有 color 配置。

@Flower-And-You
Copy link
Author

V4 你要把颜色菜单加入到 这个配置中。而你只配置了颜色,但菜单却隐藏了。editor.config.menus = [...]

V5 你的代码看起来没问题。你可以参考 http://106.12.198.214:8882/main/examples/menu.html 我的 demo ,里面也有 颜色 配置。

尊敬的作者,您好!感谢您的回复。
请原谅我的愚笨,根据您的指示,我依旧不能修改颜色,富文本编辑器依旧还是默认颜色。
其中V4版本中您所说的将颜色菜单加入到editor.config.menus = [...]这个配置中,我无法理解,请问是将颜色配置项以数组的形式添加吗?
editor.config.menus = [ 'bold', 'head', 'link', 'italic', 'underline', editor.config.colors = [ '#000000', '#eeece0', '#1c487f', '#4d80bf' ] ]

还是将颜色作为参数添加到其中呢?
editor.config.menus = [ 'bold', 'head', 'link', 'italic', 'underline', '#008c8c', ]

但无论是哪种我都失败了。

而V5版本您的demo我都没有看懂,背景颜色与字体颜色好像都是默认的,并没有发生改变。

@wangfupeng1988
Copy link
Collaborator

看 v5 demo http://106.12.198.214:8882/main/examples/menu.html 的源码,就这一行起作用。

    // 各个菜单的配置
    editorConfig.MENU_CONF['color'] = {
      colors: ['#000', '#333', '#999', '#ccc']
    }

@wangfupeng1988
Copy link
Collaborator

若用 v4 ,你要把颜色的菜单给配置上

    // 配置菜单栏,删减菜单,调整顺序
    editor.config.menus = [
        'bold',
        'head',
        'link',
        'italic',
        'underline',
        'foreColor', // 这个
        'backColor', // 这个
    ]

@Flower-And-You
Copy link
Author

若用 v4 ,你要把颜色的菜单给配置上

    // 配置菜单栏,删减菜单,调整顺序
    editor.config.menus = [
        'bold',
        'head',
        'link',
        'italic',
        'underline',
        'foreColor', // 这个
        'backColor', // 这个
    ]

依旧没有效果,这是我的全部代码,为了看出效果,颜色全部都是深色,但最终依旧没有生效

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>wangEditor-V4</title>
    <style>
        .body {
            display: flex;
            flex-direction: column;
            justify-content: center;
            min-height: 100vh;
        }

    </style>
</head>

<body>
    <div class="body">
        <div id="div1">
            <p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
        </div>
    </div>
</body>

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/wangeditor@latest/dist/wangEditor.min.js"></script>
<script type="text/javascript">
    const E = window.wangEditor
    const editor = new E("#div1")
    // 或者 const editor = new E(document.getElementById('div1'))

    // 配置菜单栏,删减菜单,调整顺序
    editor.config.menus = [
        'bold',
        'head',
        'link',
        'italic',
        'underline',
        'foreColor', // 这个
        'backColor', // 这个
    ]

    // 配置颜色(文字颜色、背景色)
    editor.config.colors = [
        '#DC143C',
        '#8B008B',
        '#4B0082',
        '#0000FF'
    ]

    editor.create()
</script>

</html>

hopm3-ymy8t

我不清楚自己到底哪里错了

@wangfupeng1988
Copy link
Collaborator

你点开下图的这俩菜单看看

image

配置的是菜单的可选颜色,并不是配置整个文本的颜色。

@wangfupeng1988
Copy link
Collaborator

如果你想配置文本的默认颜色,可以使用 v5 ,参考 wangeditor-team/wangEditor-v5#242

将其中的 fontFamily: '黑体' 改为 color: 'red' 即可。

@Flower-And-You
Copy link
Author

你点开下图的这俩菜单看看

image

配置的是菜单的可选颜色,并不是配置整个文本的颜色。

我想,我明白了,是我对文档的的理解有误,造成了这样事情,我很抱歉。

感谢wangEditor团队的无私奉献,感谢作者的耐心解答与指导,祝wangEditor越来越好!

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

No branches or pull requests

2 participants