Formily使用问题
1.select 下拉框数据
🔍我想把外面jsObject的内容,放到里面select组件的可选项中,怎么办?
可以试试下面这个处理方案
- 在fomliy初始化数据表单项中传入,自定义的option
 (3) (2).png)
- 在Select组件自定义的响应器配置中,给dataSource赋值
 (2).png)
调用接口,初始化select可选项,怎么办?
 (4).png)
2.只要包含上传文件的组件,提交就报错
 (2) (2).png)
使用 自定义请求
customRequest
替代默认的上传事件$props({
customRequest(options) {
let params = new FormData()
// post 参数
params.append("files", options.file) // binary
$request("http://upload_server/upload", {
data: params,
method: "post",
}).then(response) {
const res = JSON.parse(response)
options.onSuccess(res[0], options.file)
$self.loading = false
// 设置form表单的file字段,为接口返回的url
$form.setValuesIn("file", file[0].response.data)
}
},
})