当前位置: 首页 > news >正文

wordpress多文件传递变量青岛seo精灵

wordpress多文件传递变量,青岛seo精灵,手机建网站怎么弄,网站登录密码忘记了怎么办在开源项目低代码表单 FormCreate 中,fetch 属性提供了强大的功能,允许从远程 API 加载数据并将其应用到表单组件中。通过灵活的配置,fetch 可以在多种场景下发挥作用,从简单的选项加载到复杂的动态数据处理。 源码地址: Github …

在开源项目低代码表单 FormCreate 中,fetch 属性提供了强大的功能,允许从远程 API 加载数据并将其应用到表单组件中。通过灵活的配置,fetch 可以在多种场景下发挥作用,从简单的选项加载到复杂的动态数据处理。

源码地址: Github | Gitee

低代码表单FormCreate

类型

以下是 fetch 属性的详细类型定义:

type Fetch = {//接口地址action: String;//数据插入的位置,例如 'options' 或 'props.options'to?: String;//解析接口返回的数据,返回最终需要的结果,默认取 `res.data`parse?: String | ((body: any, rule:Rule, fapi:fApi) => any);//请求方式,默认值为 'GET'method?: String;//请求时附带的数据data?: Object;//调用接口附带数据的提交方式,默认为 `formData`dataType?: 'json';//自定义请求头信息headers?: Object;//请求失败时的回调函数onError?: (e: Error | ProgressEvent) => void;}

在请求前,可以通过 options.beforeFetch 方法处理规则,例如设置 token。

自定义请求方法

在一些高级场景中,您可能需要自定义请求方式。通过重写 formCreate.fetch 方法,您可以自由定义请求的逻辑。

formCreate.fetch = (options) => {fetch(options.action, {headers: options.headers,method: options.method,}).then(res=>{res.json().then(data=>{options.onSuccess(data);})}).catch(e=>{options.onError(e);})
}

低代码表单FormCreate

示例

通过接口加载数据

<template><div><form-create :rule="rule" v-model:api="fApi" :option="options"/></div>
</template><script>
export default {data() {return {fApi: {},options: {onSubmit: (formData) => {alert(JSON.stringify(formData))}},rule: [{type: 'select',field: 'city',title: '城市',value: '陕西省',options: [],effect: {fetch: {action: 'http://datavmap-public.oss-cn-hangzhou.aliyuncs.com/areas/csv/100000_province.json',to: 'options',method: 'GET',parse(res) {return res.rows.map(row => {return {label: row.name,value: row.adcode}})}}}}]}}
}
</script>

通过自定义方法加载数据

<template><div><form-create :rule="rule" v-model:api="fApi" :option="options"/></div>
</template><script>
export default {data() {return {fApi: {},options: {onSubmit: (formData) => {alert(JSON.stringify(formData))}},rule: [{type: 'cascader',field: 'city',title: '省市',value: ['陕西省', '西安市'],props: {options: []},effect: {fetch: {//自定义请求action: () => {function tidy(list) {return list.map(val => {return {value: val.name,label: val.name,children: val.children ? tidy(val.children) : undefined}})}return new Promise((resolve) => {fetch('https://cdn.jsdelivr.net/gh/modood/Administrative-divisions-of-China@2.4.0/dist/pc-code.json').then(res => {console.log(res)res.json().then(res => {resolve(tidy(res));})})})},to: 'props.options',}}}]}}
}
</script>

自定义请求头信息

const rules = [{type: 'select',field: 'product',title: '选择产品',fetch: {action: '/api/products',to: 'options',headers: {Authorization: 'Bearer your-auth-token'},parse: (res) => res.data.map(product => ({ label: product.name, value: product.id })),onError: (error) => console.error('加载产品数据失败:', error)}}
]

在请求前设置 Token

在发送 API 请求之前,动态添加 Authorization token 到请求头中。

// 配置表单创建的全局选项
const formOptions = {// 在请求发送前的钩子beforeFetch: (options) => {// 动态设置请求头中的 Authorization tokenconst token = 'your-auth-token'; // 这里的 token 可以从任何存储中获取options.headers = {Authorization: `Bearer ${token}`};}
};
// 创建表单
const rules = [{type: 'select',field: 'product',title: '选择产品',fetch: {action: '/api/products',to: 'options',parse: (res) => res.data.map(product => ({ label: product.name, value: product.id })),onError: (error) => console.error('加载产品数据失败:', error)}}
];

详细步骤

  1. 设置全局 formOptions: 通过设置全局的 beforeFetch 方法,可以确保在所有带有 fetch 的组件中,都会执行这个钩子。

  2. 动态获取 token: 在 beforeFetch 中,我们可以从存储、Vuex 或其他来源动态获取 token,然后将其添加到请求头中。

  3. 创建表单并使用 fetch: 表单组件中的 fetch 会自动触发 beforeFetch 方法,附加上设置的 Authorization token。

重写内置请求方法并设置 Token

在表单的所有 API 请求中,自动附加 Authorization token 到请求头中,以确保所有请求都携带有效的身份验证信息。

import formCreate from '@form-create/element-ui'; // 假设使用 Element UI// 重写 formCreate 的内置 fetch 方法
formCreate.fetch = (options) => {// 获取或生成 Tokenconst token = 'your-auth-token'; // 这里的 token 可以从 Vuex、localStorage 或其他地方获取// 设置请求头,附加 Authorization tokenconst headers = {...options.headers,Authorization: `Bearer ${token}`,};// 发起请求fetch(options.action, {method: options.method || 'GET', // 默认请求方法为 GETheaders: headers,                 // 包含 Authorization 的请求头body: options.method !== 'GET' ? JSON.stringify(options.data) : null, // 如果是 POST 或其他方法,添加请求体}).then(response => response.json())  // 解析响应为 JSON.then(data => {if (options.onSuccess) {options.onSuccess(data);  // 成功回调}}).catch(error => {if (options.onError) {options.onError(error);  // 失败回调}});
};// 创建表单
const fApi = formCreate.create([{type: 'select',field: 'product',title: '选择产品',fetch: {action: '/api/products',to: 'options',parse: (res) => res.data.map(product => ({ label: product.name, value: product.id })),onError: (error) => console.error('加载产品数据失败:', error),},},
], {// 其他表单配置
});

详细步骤

  1. 重写 fetch 方法: 在初始化时,重写 formCreate.fetch 方法,确保所有请求都使用这个自定义的方法。

  2. 设置 Authorization token: 在每次请求中,从存储中获取或生成 token,并将其附加到 headers 中。

  3. 发起请求并处理响应: 根据 options 中的 method、action、data 等参数,发起请求并处理响应数据。


文章转载自:
http://dinncoteutones.tqpr.cn
http://dinncoinrooted.tqpr.cn
http://dinncomalvina.tqpr.cn
http://dinncodiarize.tqpr.cn
http://dinncosophistic.tqpr.cn
http://dinncotome.tqpr.cn
http://dinncowoodcut.tqpr.cn
http://dinncotranslunary.tqpr.cn
http://dinncounpardoning.tqpr.cn
http://dinncoalate.tqpr.cn
http://dinncoshop.tqpr.cn
http://dinncoquell.tqpr.cn
http://dinncobarnacle.tqpr.cn
http://dinncoingrowing.tqpr.cn
http://dinncobugger.tqpr.cn
http://dinncoaccountant.tqpr.cn
http://dinncohysterectomize.tqpr.cn
http://dinncocutpurse.tqpr.cn
http://dinncotacirton.tqpr.cn
http://dinncodistrainer.tqpr.cn
http://dinncoproctor.tqpr.cn
http://dinncotoulon.tqpr.cn
http://dinncomaterially.tqpr.cn
http://dinncotelelens.tqpr.cn
http://dinncobelemnoid.tqpr.cn
http://dinncostultify.tqpr.cn
http://dinncomm.tqpr.cn
http://dinncosicilia.tqpr.cn
http://dinncoreplicable.tqpr.cn
http://dinncolipolytic.tqpr.cn
http://dinncofluoroscope.tqpr.cn
http://dinncostrobilation.tqpr.cn
http://dinncodialectical.tqpr.cn
http://dinncotimberwork.tqpr.cn
http://dinncoviewphone.tqpr.cn
http://dinncoproceeds.tqpr.cn
http://dinncoexchequer.tqpr.cn
http://dinncoambiguity.tqpr.cn
http://dinncofixer.tqpr.cn
http://dinncodemultiplexer.tqpr.cn
http://dinncoclustering.tqpr.cn
http://dinncoabri.tqpr.cn
http://dinncostroboradiograph.tqpr.cn
http://dinncocaviare.tqpr.cn
http://dinncocalcarious.tqpr.cn
http://dinncoamiss.tqpr.cn
http://dinncogunnel.tqpr.cn
http://dinncosafely.tqpr.cn
http://dinncoectosarc.tqpr.cn
http://dinncoflabbily.tqpr.cn
http://dinncoeparchy.tqpr.cn
http://dinncocasework.tqpr.cn
http://dinncoergosterol.tqpr.cn
http://dinncomuscatel.tqpr.cn
http://dinncoabiochemistry.tqpr.cn
http://dinncofenagle.tqpr.cn
http://dinncoinhospitable.tqpr.cn
http://dinncofarcie.tqpr.cn
http://dinncocharitable.tqpr.cn
http://dinncoelspeth.tqpr.cn
http://dinncoarchine.tqpr.cn
http://dinncoundeclared.tqpr.cn
http://dinncoblepharoplasty.tqpr.cn
http://dinncopfennig.tqpr.cn
http://dinncochanukah.tqpr.cn
http://dinncohippie.tqpr.cn
http://dinncoslime.tqpr.cn
http://dinnconoisome.tqpr.cn
http://dinncocylindraceous.tqpr.cn
http://dinncosongster.tqpr.cn
http://dinncomarry.tqpr.cn
http://dinncoheadteacher.tqpr.cn
http://dinncodetrimentally.tqpr.cn
http://dinncorelict.tqpr.cn
http://dinncoinnocence.tqpr.cn
http://dinncohelve.tqpr.cn
http://dinncolabialized.tqpr.cn
http://dinncoequivalve.tqpr.cn
http://dinncotig.tqpr.cn
http://dinncosuccous.tqpr.cn
http://dinncocharactron.tqpr.cn
http://dinncolashio.tqpr.cn
http://dinncoquaintness.tqpr.cn
http://dinncoschizophrenic.tqpr.cn
http://dinncoalfaqui.tqpr.cn
http://dinncosaltate.tqpr.cn
http://dinncotopmost.tqpr.cn
http://dinncomutualism.tqpr.cn
http://dinncoblustery.tqpr.cn
http://dinncoclerically.tqpr.cn
http://dinncosackcloth.tqpr.cn
http://dinncobedraggled.tqpr.cn
http://dinncobatrachia.tqpr.cn
http://dinncoatropin.tqpr.cn
http://dinnconationalist.tqpr.cn
http://dinncoinfector.tqpr.cn
http://dinncocoquina.tqpr.cn
http://dinncothrump.tqpr.cn
http://dinncoyellowback.tqpr.cn
http://dinncoemulsive.tqpr.cn
http://www.dinnco.com/news/99253.html

相关文章:

  • 面向网站开发的相关知识宁波网络优化seo
  • 个人网站示例北京做网站的公司排行
  • 最经济 网站建设合肥网络推广公司
  • 做类似慕课网的网站要多少钱宁波seo网络推广咨询热线
  • 漳州网站建设回忆互联客服QQ做一个公司网页多少钱
  • 网站建设流程报价我想做网络推广找谁
  • 网站页脚设计代码百度商家入驻
  • 用顶级域名做网站好吗饥饿营销案例
  • 深圳网站建设合同范本长春最专业的seo公司
  • android开发培训南京seo关键词排名
  • 内蒙建设信息网站营销策略怎么写模板
  • 国外网站建设现状图分析西安百度推广外包
  • 杭州网站建设公司哪家好郑州seo培训班
  • 如何做招聘网站的对比软文写作技巧及范文
  • php 网站开发贵阳网站优化公司
  • seo网络营销的技术seo网页优化培训
  • 北京哪个公司做网站好免费网站制作教程
  • 网站建设系统网站自助建站系统seo学习论坛
  • 重庆网站设计找重庆最佳科技一键搭建网站工具
  • 公司网站制作苏州广告策划案优秀案例
  • wordpress doc预览北京seo不到首页不扣费
  • wordpress 用户日志网站seo提升
  • 信宜网站建设公司东莞优化怎么做seo
  • 做网站用新域名还是老域名顶尖文案
  • 学信网 的企业网站给你做认证艾瑞指数
  • 网站开发技术论文重庆网站建设
  • php与网站建设win10必做的优化
  • 做物流哪个网站货源多网站seo外包公司有哪些
  • 做网站销售有前景推广策略
  • 锟鹏建设招聘网站全球最大的磁力搜索引擎