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

resource里面的定义的fields和block里面定义的fields已经区块实例里面的fields(在actions里面的通过this.fields)的区别? #96

Open
EdwardQ opened this issue Jan 2, 2020 · 2 comments

Comments

@EdwardQ
Copy link

EdwardQ commented Jan 2, 2020

image

@EdwardQ
Copy link
Author

EdwardQ commented Jan 2, 2020

1、resource里面的fields是关于字段的定义,可以使用ams.resource定义来公用资源

2、block里面的fields是当前区块对于字段的定义,当区块里面指定resource时,优先级 bolck.field > resource.field

3、区块的vue实例里面fields会混合resource.fields和当前block.fields配置生成一份用于交互渲染的fields,放于实例的fields里面,所以需要动态的修改field的属性实现一些交互行为需要用this.fields.xxx或者ams.$block.blockName.fields.xxx来修改

如图:
image

@EdwardQ
Copy link
Author

EdwardQ commented Jan 2, 2020

ams.block('form', {
    resource: {
        api: {
            ...
        },
        fields: {
            switch: {
                type: 'switch',
                label: '切换'
            },
            input: {
                type: 'text',
                label: '文字'
            }
        }
    },
    ctx: 'view',
    type: 'form',
    fields: {
        input: {
            label: '文字2'
        }
    },
    actions: {
        fieldChange({ name, value, path}){
            if (name === 'switch') {
                this.fields.input.props.disable = !!value
            }
        }
    }
})

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