Closed lsm2208911 closed 7 months ago
第一步:
<form-create name="form" v-model="fApi" :rule="rule" :option="option" :value.sync="value"></form-create>
在form-create
组件上添加name属性, 然后 remoteMethod 就可以通过 formCreate.getApi('form')可以获取API
第二步:
使用form-create
组件的全局API fetch
,去远程搜索,具体代码:
formCreate.fetch({
action: 'http://localhost:8073/getSchools?currentPage=1&pageSize=10&name=' + query,
onSuccess: function(resp){
const list = resp.data.map(item => {
return {
value: item.userId,
label: item.departName
}
})
api.updateRule('schoolId', {
options: list
})
}
})
}
json:
"remoteMethod": " function(query) {\n const api = formCreate.getApi('form')\n formCreate.fetch({\n action: 'http://localhost:18073/getSchools?currentPage=1&pageSize=10&name=' + query,\n onSuccess: function(resp){\n const list = resp.data.map(item => {\n return {\n value: item.userId,\n label: item.departName\n }\n })\n api.updateRule('schoolId', {\n options: list\n })\n }\n })\n }"
就是看起来很费劲,如果有更好的显示请告诉我!
@form-create/element-ui@2.5.33
我不太了解配置
effect -> fetch
意义,fetch
是只会执行一次吗?还是像一个方法一样,可以进行调用,比如我想在remoteMethod
中再次执行fetch
发送请求? 如果不是,那么我想在remoteMethod
中执行我项目中的axios get方法,应该怎么样写?能给一个例子吗?