export interface ChatIm { brokerName: string phone: string brokerId: string brokerImg: string cityId: string houseInfo: string msg: string } export function launchChatActionCallBack(params: ChatIm) { const webViewEnv = getWebViewEnv() if (webViewEnv === WebViewEnv.IOS) { window.launchCardChatCallBack( params.brokerName, params.phone, params.brokerId, params.brokerImg, params.cityId, params.houseInfo, params.msg, ) }else{ wx.miniProgram.navigateTo({ url: `/pages/im/im?bid=${params.brokerId}&cityId=${ params.cityId }&sendWords=communitycheck&wMsg=${encodeURIComponent(params.msg)}`, }) } } 在vue3、ts项目汇总,以上方法 如何添加一个不确定有没有的参数,如果有该参数就传过去和拼在ur上,如果没有就不传
时间: 2024-03-01 18:50:50 浏览: 63
可以在 `params` 中添加一个可选的参数,然后在判断是否存在该参数后进行拼接。例如:
```
export interface ChatIm {
brokerName: string;
phone: string;
brokerId: string;
brokerImg: string;
cityId: string;
houseInfo: string;
msg: string;
optionalParam?: string; // 可选参数
}
export function launchChatActionCallBack(params: ChatIm) {
const webViewEnv = getWebViewEnv();
if (webViewEnv === WebViewEnv.IOS) {
window.launchCardChatCallBack(
params.brokerName,
params.phone,
params.brokerId,
params.brokerImg,
params.cityId,
params.houseInfo,
params.msg,
params.optionalParam // 如果有可选参数,就拼接
);
} else {
let url = `/pages/im/im?bid=${params.brokerId}&cityId=${params.cityId}&sendWords=communitycheck&wMsg=${encodeURIComponent(params.msg)}`;
if (params.optionalParam) { // 如果有可选参数,就拼接
url += `&optionalParam=${encodeURIComponent(params.optionalParam)}`;
}
wx.miniProgram.navigateTo({ url });
}
}
```
阅读全文