这几次用jsx写法书写elementui组件,发现修改组件中的props里的属性不生效,后来发现写法不对
错误写法:
const adom = [
{
type: 'el-cascader',
label: '部门',
prop: 'dept',
render: () => {
return (
this.deptOptions.length > 0 &&
<el-cascader
vModel={this.formData.deptCode}
options={this.deptOptions}
props={{value: 'code', label: 'name', children: 'children'}}
clearable
filterable
placeholder="请选择部门"
></el-cascader>
)
},
},
]
正确写法
const adom = [
{
type: 'el-cascader',
label: '部门',
prop: 'dept',
render: () => {
return (
this.deptOptions.length > 0 &&
<el-cascader
vModel={this.formData.deptCode}
options={this.deptOptions}
props={{
props: { value: 'code', label: 'name', children: 'children' },
}}
clearable
filterable
placeholder="请选择部门"
></el-cascader>
)
},
},
]
同时里面el-cascader里的其他属性也可以放到props里
<el-cascader
props={{
value: this.formData.deptCode,
options: this.deptOptions,
props: { value: 'code', label: 'name', children: 'children' },
clearable: true,
filterable: true,
placeholder: '请选择部门',
}}
></el-cascader>