# update v2.5.0+
当value
或link
中配置的field
的value
发生变化时会触发update
回调, 可以在update
回调中做一些关于value
的联动处理
# 类型
type update = (val:any, rule:FormRule, fApi:fApi)=>Boolean|void
# 示例
# 修改value
为组件的title
<template>
<div>
<form-create :rule="rule" v-model="fApi" :option="options"/>
</div>
</template>
<script>
export default {
data(){
return {
fApi:{},
options:{
onSubmit:(formData)=>{
alert(JSON.stringify(formData))
}
},
rule:[
{
type:'input',
field: 'default',
title:'update',
value:'default',
update(val, rule){
rule.title = val
}
}
]
}
}
}
</script>
# 当 input1
发生变化时触发input2
的回调
link
配置示例
<template>
<div>
<form-create :rule="rule" v-model="fApi" :option="options"/>
</div>
</template>
<script>
export default {
data(){
return {
fApi:{},
options:{
onSubmit:(formData)=>{
alert(JSON.stringify(formData))
}
},
rule:[
{
type:'input',
field: 'input1',
title:'input1',
value:'default'
},
{
type:'input',
field: 'input2',
title:'input1',
link:['input1'],
value:'',
update(val, rule){
rule.title = '' + Date.now()
}
},
]
}
}
}
</script>
# 当input
值为空时隐藏组件
<template>
<div>
<form-create :rule="rule" v-model="fApi" :option="options"/>
</div>
</template>
<script>
export default {
data(){
return {
fApi:{},
options:{
onSubmit:(formData)=>{
alert(JSON.stringify(formData))
}
},
rule:[
{
type:'input',
field:'input',
title:'input',
value:'show',
update(val){
return !val
}
},
]
}
}
}
</script>