xaboy / form-create

:fire::fire::fire: 强大的低代码动态表单组件,通过数据驱动表单渲染,适配移动端,支持可视化设计。提高开发者对表单的开发效率。目前在政务系统、OA系统、ERP系统、电商系统、流程管理等系统中已稳定应用。
https://www.form-create.com/
MIT License
5.97k stars 960 forks source link

Select组件使用Effect获取数据后,在Update中无法获取Options #691

Closed zhang-huan-1990 closed 4 months ago

zhang-huan-1990 commented 5 months ago

使用Select配置了Effect来获取数据,期望其他组件更新可以更新该Select的Options,但是在update函数里无法获取到该rule的Options数据

new Vue({
  el: '#app',
  data(){
            return {
                fApi:{},
                options:{
                    onSubmit:(formData)=>{
                        alert(JSON.stringify(formData))
                    }
                },
                rule:[
                    {
                        type:'cascader',
                        field:'city',
                        title:'city',
                        value:[],
                        props:{
                            options:[]
                        },
                        update(val,_rule,fApi){
                          //此处optiosn和props.options都没有值
                          console.log(_rule.options)
                        },
                        effect:{
                            fetch: {
                                action:'https://cdn.jsdelivr.net/gh/modood/Administrative-divisions-of-China@2.4.0/dist/pc-code.json',
                                to: 'props.options',
                                method:'GET',
                                parse(res){
                                    function tidy(list){
                                        return list.map(val=>{
                                            return {
                                                value:val.code,
                                                label:val.name,
                                                children:val.children ? tidy(val.children) : undefined
                                            }
                                        })
                                    }

                                    return tidy(res);
                                }
                            }
                        }
                    }
                ]
            }

        }
})
zhang-huan-1990 commented 5 months ago

我已经配置了 to: 'props.options', 似乎这个配置没有生效。

xaboy commented 4 months ago

下个版本会增加api.getRenderRule方法, 可以获取到最终完整的rule @zhang-huan-1990