interface.uts 8.8 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1
type $OnCallback = Function
DCloud-yyl's avatar
DCloud-yyl 已提交
2
export type $On = (eventName: string, callback: $OnCallback) => number
DCloud-yyl's avatar
DCloud-yyl 已提交
3 4

type $OnceCallback = Function
DCloud-yyl's avatar
DCloud-yyl 已提交
5
export type $Once = (eventName: string, callback: $OnceCallback) => number
DCloud-yyl's avatar
DCloud-yyl 已提交
6

DCloud-yyl's avatar
DCloud-yyl 已提交
7
export type $Off = (eventName: string, callback?: any | null) => void
DCloud-yyl's avatar
DCloud-yyl 已提交
8

DCloud-yyl's avatar
DCloud-yyl 已提交
9
export type $Emit = (eventName: string, ...args: Array<any | null>) => void
DCloud-yyl's avatar
DCloud-yyl 已提交
10 11 12 13

export interface Uni {
    /**
     * 监听自定义事件。事件可以由 uni.$emit 触发。回调函数会接收 uni.$emit 传递的参数。
DCloud-yyl's avatar
DCloud-yyl 已提交
14
     * 4.31+ 开始支持返回事件监听器 id, 用于 off 事件监听器。
DCloud-yyl's avatar
DCloud-yyl 已提交
15
     *
DCloud-yyl's avatar
DCloud-yyl 已提交
16
     * @tutorial-uni-app-x https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#on
DCloud-yyl's avatar
DCloud-yyl 已提交
17
     * @tutorial https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#on
DCloud-yyl's avatar
DCloud-yyl 已提交
18
     * @tutorial-uni-app https://uniapp.dcloud.net.cn/api/window/communication.html#on
DCloud-yyl's avatar
DCloud-yyl 已提交
19 20 21 22 23 24 25 26 27 28
     * @uniPlatform {
     *  "app": {
     *    "android": {
     *      "osVer": "5.0",
     *      "uniVer": "√",
     *      "unixVer": "3.91"
     *    },
     *    "ios": {
     *      "osVer": "12.0",
     *      "uniVer": "√",
DCloud-yyl's avatar
DCloud-yyl 已提交
29 30
     *      "unixVer": "4.11",
     *      "unixUtsPlugin": "4.31"
DCloud-yyl's avatar
DCloud-yyl 已提交
31 32 33 34 35
     *    },
     *    "harmony": {
     *      "osVer": "3.0",
     *      "uniVer": "4.23",
     *      "unixVer": "x"
DCloud-yyl's avatar
DCloud-yyl 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
     *    }
     *  },
     *  "mp": {
     *    "weixin": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "alipay": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "baidu": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "toutiao": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "lark": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "qq": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "kuaishou": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "jd": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    }
     *  },
     *  "web": {
     *    "uniVer": "√",
     *    "unixVer": "4.0"
     *  }
     * }
DCloud-yyl's avatar
DCloud-yyl 已提交
85 86
     * @param eventName 事件名称
     * @param callback 事件回调
DCloud-yyl's avatar
DCloud-yyl 已提交
87
     */
DCloud-yyl's avatar
DCloud-yyl 已提交
88
    $on(eventName: string, callback: $OnCallback): number
DCloud-yyl's avatar
DCloud-yyl 已提交
89 90 91
    /**
     * 移除自定义事件监听器。如果提供了事件名和回调,则只移除这个回调的监听器。
     * 4.13+ 开始支持第二个参数为可选,如果仅提供事件名,则移除该事件的所有监听器。
DCloud-yyl's avatar
DCloud-yyl 已提交
92
     * 4.31+ 开始第二个参数的类型由 `Function | null` 调整为 `any | null`, 支持传入 `uni.$on`、`uni.$once` 返回的事件监听器 id, 移除指定事件监听器。
DCloud-yyl's avatar
DCloud-yyl 已提交
93
     * @tutorial-uni-app-x https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#off
DCloud-yyl's avatar
DCloud-yyl 已提交
94
     * @tutorial https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#off
DCloud-yyl's avatar
DCloud-yyl 已提交
95
     * @tutorial-uni-app https://uniapp.dcloud.net.cn/api/window/communication.html#off
DCloud-yyl's avatar
DCloud-yyl 已提交
96 97 98 99 100 101 102 103 104 105
     * @uniPlatform {
     *  "app": {
     *    "android": {
     *      "osVer": "5.0",
     *      "uniVer": "√",
     *      "unixVer": "3.91"
     *    },
     *    "ios": {
     *      "osVer": "12.0",
     *      "uniVer": "√",
DCloud-yyl's avatar
DCloud-yyl 已提交
106 107
     *      "unixVer": "4.11",
     *      "unixUtsPlugin": "4.31"
DCloud-yyl's avatar
DCloud-yyl 已提交
108 109 110 111 112
     *    },
     *    "harmony": {
     *      "osVer": "3.0",
     *      "uniVer": "4.23",
     *      "unixVer": "x"
DCloud-yyl's avatar
DCloud-yyl 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
     *    }
     *  },
     *  "mp": {
     *    "weixin": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "alipay": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "baidu": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "toutiao": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "lark": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "qq": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "kuaishou": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "jd": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    }
     *  },
     *  "web": {
     *    "uniVer": "√",
     *    "unixVer": "4.0"
     *  }
     * }
DCloud-yyl's avatar
DCloud-yyl 已提交
162 163
     * @param eventName 事件名称
     * @param callback 要移除的事件回调或事件监听器 id
DCloud-yyl's avatar
DCloud-yyl 已提交
164
     */
DCloud-yyl's avatar
DCloud-yyl 已提交
165
    $off(eventName: string, callback?: any | null): void
DCloud-yyl's avatar
DCloud-yyl 已提交
166 167
    /**
     * 监听一个自定义事件。事件只触发一次,在第一次触发之后移除事件监听器。
DCloud-yyl's avatar
DCloud-yyl 已提交
168
     * 4.31+ 开始支持返回事件监听器 id, 用于 off 事件监听器。
DCloud-yyl's avatar
DCloud-yyl 已提交
169
     *
DCloud-yyl's avatar
DCloud-yyl 已提交
170
     * @tutorial-uni-app-x https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#once
DCloud-yyl's avatar
DCloud-yyl 已提交
171
     * @tutorial https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#once
DCloud-yyl's avatar
DCloud-yyl 已提交
172
     * @tutorial-uni-app https://uniapp.dcloud.net.cn/api/window/communication.html#once
DCloud-yyl's avatar
DCloud-yyl 已提交
173 174 175 176 177 178 179 180 181 182
     * @uniPlatform {
     *  "app": {
     *    "android": {
     *      "osVer": "5.0",
     *      "uniVer": "√",
     *      "unixVer": "3.91"
     *    },
     *    "ios": {
     *      "osVer": "12.0",
     *      "uniVer": "√",
DCloud-yyl's avatar
DCloud-yyl 已提交
183 184
     *      "unixVer": "4.11",
     *      "unixUtsPlugin": "4.31"
DCloud-yyl's avatar
DCloud-yyl 已提交
185 186 187 188 189
     *    },
     *    "harmony": {
     *      "osVer": "3.0",
     *      "uniVer": "4.23",
     *      "unixVer": "x"
DCloud-yyl's avatar
DCloud-yyl 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
     *    }
     *  },
     *  "mp": {
     *    "weixin": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "alipay": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "baidu": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "toutiao": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "lark": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "qq": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "kuaishou": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "jd": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    }
     *  },
     *  "web": {
     *    "uniVer": "√",
     *    "unixVer": "4.0"
     *  }
     * }
DCloud-yyl's avatar
DCloud-yyl 已提交
239 240
     * @param eventName 事件名称
     * @param callback 事件回调
DCloud-yyl's avatar
DCloud-yyl 已提交
241
     */
DCloud-yyl's avatar
DCloud-yyl 已提交
242
    $once(eventName: string, callback: $OnceCallback): number
DCloud-yyl's avatar
DCloud-yyl 已提交
243 244 245
    /**
     * 触发自定义事件,附加的参数会传递给事件监听器。
     *
DCloud-yyl's avatar
DCloud-yyl 已提交
246
     * @tutorial-uni-app-x https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#emit
DCloud-yyl's avatar
DCloud-yyl 已提交
247
     * @tutorial https://doc.dcloud.net.cn/uni-app-x/api/event-bus.html#emit
DCloud-yyl's avatar
DCloud-yyl 已提交
248
     * @tutorial-uni-app https://uniapp.dcloud.net.cn/api/window/communication.html#emit
DCloud-yyl's avatar
DCloud-yyl 已提交
249 250 251 252 253 254 255 256 257 258
     * @uniPlatform {
     *  "app": {
     *    "android": {
     *      "osVer": "5.0",
     *      "uniVer": "√",
     *      "unixVer": "3.91"
     *    },
     *    "ios": {
     *      "osVer": "12.0",
     *      "uniVer": "√",
DCloud-yyl's avatar
DCloud-yyl 已提交
259 260
     *      "unixVer": "4.11",
     *      "unixUtsPlugin": "4.31"
DCloud-yyl's avatar
DCloud-yyl 已提交
261 262 263 264 265
     *    },
     *    "harmony": {
     *      "osVer": "3.0",
     *      "uniVer": "4.23",
     *      "unixVer": "x"
DCloud-yyl's avatar
DCloud-yyl 已提交
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
     *    }
     *  },
     *  "mp": {
     *    "weixin": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "alipay": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "baidu": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "toutiao": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "lark": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "qq": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "kuaishou": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    },
     *    "jd": {
     *      "hostVer": "√",
     *      "uniVer": "√",
     *      "unixVer": "x"
     *    }
     *  },
     *  "web": {
     *    "uniVer": "√",
     *    "unixVer": "4.0"
     *  }
     * }
DCloud-yyl's avatar
DCloud-yyl 已提交
315 316
     * @param eventName 事件名称
     * @param args 触发事件时传递的参数
DCloud-yyl's avatar
DCloud-yyl 已提交
317
     */
DCloud-yyl's avatar
DCloud-yyl 已提交
318
    $emit(eventName: string, ...args: Array<any | null>): void
DCloud-yyl's avatar
DCloud-yyl 已提交
319
}