# @iwux/webview

> { "usingComponents": { "wux-webview": "@iwux/webview" } }

Latest version **1.0.83** (published 2021-04-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install @iwux/webview
pnpm add @iwux/webview
yarn add @iwux/webview
bun add @iwux/webview
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.83 |
| Published | 2021-04-26 |
| First published | 2021-04-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tianyingchun |

## Links

- npm: https://www.npmjs.com/package/@iwux/webview
- npm.io page: https://npm.io/package/@iwux/webview

## Dependencies (1)

- [@iwux/helpers](https://npm.io/package/@iwux/helpers.md) ^1.0.83

## Recent versions

- 1.0.83 (latest) — 2021-04-26

## README

# usage

<!-- .json -->
{
  "usingComponents": {
    "wux-webview": "@iwux/webview"
  }
}

<!-- 使用 wux-webview 创建一个 webview 页面 -->
<!-- 接受 src 参数，传入 webviewConfigs 来启动 wux-webview -->

<!-- .js -->
Page({
  data:{
    webviewConfigs: {
      src: 'https://m.ly.com',
      title: '',
      backgroundColor: '',  // 配置导航
      frontColor: '',
      hideShareMenu: false,
      shareConfigs: {},     // 配置分享
      isThirdUrl: false,    // 第三方页面，则不会在 src 地址上拼接参数
      appendNewCode: false, // 添加code
    },
  },
  onLoad(options) {
    <!-- 其他页面传入src，打开此页面，此页面将 src传给 <wux-webview /> -->
    const src = decodeURIComponent(options && options.src || '');
    const { webviewConfigs } = this.data;
    webviewConfigs.src = src;
    this.setData({ webviewConfigs });
  },
  onBindmessage(e){
    <!-- 分享，页面注销触发，将数据存储在storage -->
    <!-- 此页面关闭后，上个页面 或 下个页面在onShow函数取数据 -->
    const cbData = e.detail;
    if (Object.keys(cbData).length) {
      attachStackData(cbData);
    }
  },
});

<!-- 使用方式 -->
<!-- step1: openWebview() 打开webview -->
<!-- step2: onShow() 中获取数据 -->
Page({
  onShow() {
    const cbData = getStackData();
    if (Object.keys(cbData).length) {
      console.log('== postMessage callBack', cbData);
    }
  },
  openWebview() {
    wx.navigateTo({
      url: `/webview/index?src=${encodeURIComponent('https://jr.qa.ly.com/webapps/baitiao/wxapp/_tools/index-dev?env=inte')}`,
    });
  },
});

<!-- .wxml -->
<wux-webview config="{{ webviewConfigs }}" bind:bindmessage="onBindmessage" />

---
_Source: https://npm.io/package/@iwux/webview · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
