DualWield
V2EX  ›  问与答

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

  •  
  •   DualWield · Dec 3, 2021 · 887 views
    This topic created in 1645 days ago, the information mentioned may be changed or developed.

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

    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
       Dec 6, 2021
    所以周五晚上发帖,帖子就很容易沉了吗。。。。
    DualWield
        2
    DualWield  
    OP
       Oct 24, 2022
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2721 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 242ms · UTC 15:12 · PVG 23:12 · LAX 08:12 · JFK 11:12
    ♥ Do have faith in what you're doing.