欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 焦点 > vue3 传参 传入变量名

vue3 传参 传入变量名

2025/5/4 14:34:56 来源:https://blog.csdn.net/weixin_45024453/article/details/147336933  浏览:    关键词:vue3 传参 传入变量名

背景:

需求是:在vue框架中,接口传参我们需要穿“变量名”,而不是字符串

通俗点说法是:在网络接口请求的时候,要传属性名

效果展示:

vue2核心代码:

this[_keyParam]

vue3核心代码:

[_keyParam] 

//封装方法
const filtertreeLocationSelect =  async(filterVal, item )=> {if (!filterVal) return;const _keyParam = item.filterablePrama.keyParam// console.log('_key>>>',_keyParam,typeof _keyParam,33,this[_keyParam]);console.log('_key>>>',_keyParam,typeof _keyParam,33,[_keyParam]);//后端接口await handleSubFilter(item, {[_keyParam] : filterVal });
};

完整使用案列:


const item = {type: "treeLocationSelect",label: "渡口名称",key: "dkId",url: "/data/ferryPort/pageData",methed: "post",optionParam: {label: "name",value: "pid",},optionsData: [],moreparams: {pageNum: 1,pageSize: 99999,},headers: {headers: {"Content-Type": "application/json",},},default: store.selectAreaId,limit: "有联动",filterable: true,filterablePrama:{keyParam:'name'},},
//调用封装方法:
filtertreeLocationSelect(filterVal,item )

 

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词