UNPKG

2.4 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction } from './common'
3interface WebViewProps extends StandardProps {
4 /** webview 指向网页的链接。可打开关联的公众号的文章,其它网页需登录小程序管理后台配置业务域名。
5 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
6 */
7 src: string
8 /** webview 的进度条颜色
9 * @supported tt
10 */
11 progressbarColor?: string
12 /** 若使用web-view组件引入第三方客服,必须填写type="im"
13 * @supported tt
14 * @default default
15 */
16 type?: string
17 /** 网页向小程序 postMessage 时,会在特定时机(小程序后退、组件销毁、分享)触发并收到消息。e.detail = { data }
18 * @supported weapp, alipay, swan, tt, qq, jd
19 */
20 onMessage?: CommonEventFunction<WebViewProps.onMessageEventDetail>
21 /** 网页加载成功时候触发此事件。e.detail = { src }
22 * @supported weapp, alipay, tt, qq, h5, rn, harmony_hybrid
23 */
24 onLoad?: CommonEventFunction<WebViewProps.onLoadEventDetail>
25 /** 网页加载失败的时候触发此事件。e.detail = { src }
26 * @supported weapp, alipay, tt, qq, h5, rn, harmony_hybrid
27 */
28 onError?: CommonEventFunction<WebViewProps.onErrorEventDetail>
29}
30declare namespace WebViewProps {
31 interface onMessageEventDetail {
32 /** 消息数据,是多次 postMessage 的参数组成的数组 */
33 data: any[]
34 }
35 interface onLoadEventDetail {
36 /** 网页链接 */
37 src: string
38 }
39 interface onErrorEventDetail {
40 /** 网页链接 */
41 src: string
42 }
43}
44/** web-view 组件是一个可以用来承载网页的容器,会自动铺满整个小程序页面。个人类型与海外类型的小程序暂不支持使用。
45 * @classification open
46 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony, harmony_hybrid
47 * @example_react
48 * ```tsx
49 * class App extends Component {
50 * handleMessage () {}
51 *
52 * render () {
53 * return (
54 * <WebView src='https://mp.weixin.qq.com/' onMessage={this.handleMessage} />
55 * )
56 * }
57 * }
58 * ```
59 * @example_vue
60 * ```html
61 * <template>
62 * <web-view src='https://mp.weixin.qq.com/' `@message="handleMessage" />
63 * </template>
64 * ```
65 * @see https://developers.weixin.qq.com/miniprogram/dev/component/web-view.html
66 */
67declare const WebView: ComponentType<WebViewProps>
68export { WebView, WebViewProps }