has.switchTab(Object object)
如果应用定义了多标签(tab),即客户端窗口的底部或顶部有可切换页面的标签(tab),那么可以通过此接口跳转到tabBar页面,同时关闭其他所有非tabBar页面。
起始版本: 1.0.0
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| url | string | 是 | 需要跳转的tabBar页面路径(需要在app.json的tabbar字段定义的页面),路径后不能带参数。 支持格式:(假设app.json的tabbar字段定义了页面: "page/tab1/tab1") 1. 以"/"开头,加上tabbar字段定义的页面路径;例如:"/page/tab1/tab1"。 2. 其他路径,例如:tab1、./tab1、../tab1。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码信息:
| 错误码 | 错误信息 |
|---|---|
| 102 | Parameter error. Possible causes: 1.url is invalid. 2.current path error. |
| 20000201 | switchTab error. |
示例:
app.json中定义tabbar:
"tabBar": {
"list": [
{
"pagePath": "page/tabbar1/tabbar1",
"text": "tabbar1",
"iconPath": "image/icon_tabbar1.png",
"selectedIconPath": "image/icon_tabbar1_HL.png"
},
{
"pagePath": "page/tabbar2/tabbar2",
"iconPath": "image/icon_tabbar2.png",
"selectedIconPath": "image/icon_tabbar1_HL.png",
"text": "tabbar2"
}
]
} 调用接口:
has.switchTab({
url: '/page/tabbar1/tabbar1',
success: (res) => {
console.info('switchTab success', res);
},
fail: (err) => {
console.error('switchTab fail', err);
},
complete: (res) => {
console.info('switchTab complete', res);
}
}); has.reLaunch(Object object)
关闭所有页面,打开应用内的某个页面。
起始版本: 1.0.0
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| url | string | 是 | 需要跳转的应用内页面路径(在app.json中定义的代码包路径),页面路径后可以带参数。参数与路径之间用?分隔,参数与键值用=相连,多个参数用&分隔。 支持格式:(假设app.json中定义了页面: "page/path/path") 1. 以"/"开头,是全局路径。 2. 其他路径,例如:a.png、./a.png、../a.png。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码信息:
| 错误码 | 错误信息 |
|---|---|
| 101 | Common error. Possible causes: gotoPage fetchModule fail. |
| 102 | Parameter error. Possible causes: 1.url is invalid. 2.current path error. 3.page not found. |
| 20000501 | reLaunch error. |
示例:
调用接口:
has.reLaunch({
url: '/page/path/path?key=1',
success: (res) => {
console.info('reLaunch success', res);
},
fail: (err) => {
console.error('reLaunch fail', err);
},
complete: (res) => {
console.info('reLaunch complete', res);
}
}); /page/path页面,options内含有路径后携带参数:
Page({
onLoad: (options) => {
console.info(options);
}
}) has.redirectTo(Object object)
关闭当前页面,跳转到应用内的某个页面,但是不允许跳转到tabBar页面。
起始版本: 1.0.0
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| url | string | 是 | 需要跳转的应用内非tabBar的页面路径(在app.json中定义的代码包路径),路径后可以带参数。参数与路径之间用?分隔,参数与键值用=相连,多个参数用&分隔。 支持格式:(假设app.json中定义了页面: "page/path/path") 1. 以"/"开头,是全局路径。 2. 其他路径,例如:a.png、./a.png、../a.png。 |
| success | function | 否 | 接口调用成功的回调函数。 |
| fail | function | 否 | 接口调用失败的回调函数。 |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行)。 |
错误码信息:
| 错误码 | 错误信息 |
|---|---|
| 101 | Common error. Possible causes: gotoPage fetchModule fail. |
| 102 | Parameter error. Possible causes: 1.url is invalid. 2.current path error. 3.tabBar url not allowed. 4.page not found. |
| 20000301 | redirectTo error. |
示例:
has.redirectTo({
url: '/page/path/path?key=1',
success: (res) => {
console.info('redirectTo success', res);
},
fail: (err) => {
console.error('redirectTo fail', err);
},
complete: (res) => {
console.info('redirectTo complete', res);
}
}); EventChannel.emit(string eventName, Object|Array|string args)
触发一个事件。
起始版本: 1.0.21
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| eventName | string | 是 | 事件名称。 |
| args | Object | Array | string | 否 | 事件参数。 |
EventChannel.on(string eventName, function fn)
持续监听一个事件。
起始版本: 1.0.21
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| eventName | string | 是 | 事件名称。 |
| fn | function | 是 | 事件监听函数。 |