Open fengbindev opened 1 year ago
自己重写formCreate.fetch
方法
修改这个文件 src/plugins/formCreate/index.ts
interface Option {
action: string
method?: AxiosMethod
data?: object
dataType?: object
headers?: object
withCredentials?: boolean
onSuccess: (body: any) => void
onError?: (e: Error | ProgressEvent) => void
_parse?: string
}
// 参考 http://www.form-create.com/v3/element-ui/auto-import.html 文档
export const setupFormCreate = (app: App<Element>) => {
components.forEach((component) => {
app.component(component.name, component)
})
formCreate.use(install)
const overrideFetch = (option: Option, effectArgs) => {
// console.log('--fetch option--', option)
serivice({
url: option.action,
method: option.method,
data: option.data,
headers: option.headers,
withCredentials: option.withCredentials
})
.then((res) => {
try {
if (option._parse) {
const parseFn = formCreate.parseFn(option._parse)
// console.log('--parseFn--', parseFn)
res.data = parseFn(res)
}
} catch (e) {
console.log('--parseFn error--', e)
}
option.onSuccess?.(res)
})
.catch((e) => {
option.onError?.(e)
})
return option
}
// 重写 fetch 请求方法,select 等动态获取数据请求通过拦截器
formCreate.fetch = overrideFetch
app.use(formCreate)
}
自己重写
formCreate.fetch
方法
请问下这个要怎么重写
@rujianwang 看一下楼上的代码, 核心就是formCreate.fetch = overrideFetch
覆盖formCreate.fetch
@rujianwang 看一下楼上的代码, 核心就是
formCreate.fetch = overrideFetch
覆盖formCreate.fetch
Vue.use(ELEMENT);
formCreate.fetch = function(option, effectArgs) { debugger; }; Vue.use(formCreate);
我在main.js里面这样写 默认不生效。我不太想 改你的源码
fc-designer的选择器组件,在加载异步数据的时候怎么操作才能解决待token得问题???就是访问异步数据接口的时候能自带vue中的token??? 如: $store.user.token ,这种方式