V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
DualWield
V2EX  ›  问与答

哪种配置的语法更让人觉得舒服?

  •  
  •   DualWield · 2021-12-03 19:10:50 +08:00 · 432 次点击
    这是一个创建于 868 天前的主题,其中的信息可能已经有所发展或是发生改变。

    一个组件可能有很多配置项,目前在想哪种配置写起来比较爽?

    const width = {
        defaultValue: 'xx',
        rules: [],
        formType: 'input',
    }
    // 这种写法,就是把一些相关的属性都配置到一个分类(比如 layout )里面
    {
        View: {
            layout: {
                width,
                height,
                top,
                left,
            },
            // 自定义配置
            font: {
                fontSize: {
                    ...fontSize,
                    ...customFontSizeOptions
                }
            }
        }
    }
    
    // 这种写法,分类放到每个里面去描述,比如 width 加一个 type: 'layout',
    {
        View: {
            width,
            height,
            top,
            left,
            // 自定义配置
            fontSize: {
                ...fontSize,
                ...customFontSizeOptions
            }
        }
    }
    
    // 这种写法,跟上面这种比较像,只是数组的写法
    {
        View: ['width', 'height', 'top', 'left', ['fontSize', customFontSizeOptions]]
    }
    
    
    
    

    个人比较偏爱第三种,感觉比较清爽

    DualWield
        1
    DualWield  
    OP
       2021-12-06 11:26:43 +08:00
    所以周五晚上发帖,帖子就很容易沉了吗。。。。
    DualWield
        2
    DualWield  
    OP
       2022-10-24 20:21:59 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1515 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 17:07 · PVG 01:07 · LAX 10:07 · JFK 13:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.