# ic-vue-share

> a wrapper based on wechat-share

Latest version **1.3.0** (published 2018-06-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install ic-vue-share
pnpm add ic-vue-share
yarn add ic-vue-share
bun add ic-vue-share
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2018-06-24 |
| First published | 2018-05-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 19.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | xxxxxMiss |
| Maintainers | qschqd |
| Keywords | wechat, share, vue |

## Links

- npm: https://www.npmjs.com/package/ic-vue-share
- Repository: https://github.com/xxxxxMiss/ic-utils/tree/master/packages/share
- npm.io page: https://npm.io/package/ic-vue-share

## Dependencies (3)

- [ic-jsonp](https://npm.io/package/ic-jsonp.md) ^1.3.0
- [ic-utils](https://npm.io/package/ic-utils.md) ^1.0.16
- [weixin-js-sdk](https://npm.io/package/weixin-js-sdk.md) ^1.3.2

## Recent versions

- 1.3.0 (latest) — 2018-06-24
- 1.0.12 — 2018-05-25
- 1.0.9 — 2018-05-23
- 1.0.4 — 2018-05-21
- 1.0.3 — 2018-05-21
- 1.0.2 — 2018-05-21
- 1.0.1 — 2018-05-20

## README

# ic-vue-share
> An module about wechat-share for rapid development.

### Install
You can get it from npm.

``` sh
$ npm i ic-vue-share || yarn add ic-vue-share
```

### Usage

``` js
import Vue from 'vue'
import IcShare from 'ic-vue-share'

Vue.use(IcShare, options)
```


### Optional param `options`
> You can passed an optional object as the second param, you can define some useful properties in the options as below:

url
> A string value for getting auth from wechat for using jsApi.
> Required. Throw an error both `authFn` and `url` are null.

authFn
> Internal, we use a jsonp function to get authentication from the specified url above. You can customize yourself's logic for authentication from server by the `authFn` function. The function must be return a promise or async function with auth-data from server. We dont supports callback form...

jsApiList
> An array of interfaces needed to be auth. More informations is [here](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115).

debug
> The option is convenient for developing. A boolean which to set by `process.env.NODE_ENV`. Thats to say, it is `false` when `process.env.NODE_ENV === 'production'`. Of course, you can explicitly passed a boolean value to it.

### shareDataConfig
> Required. An object config jsApiList data.

``` js
    {
        data () {
            return {
                shareDataConfig: {
                    onMenuShareTimeline: {
                        title: '',
                        desc: '',
                        link: '',
                        // ...
                    },
                    onMenuShareQQ: {
                        title: '',
                        desc: '',
                        imgUrl: '',
                        // ...
                    }
                }
            }
        }
    }
```

### jsApiList
> An string array of auth-interfaces. It is optional, once you config jsApi data like above, if you omited it, we get it with `Object.keys(shareDataConfig)`.
> Actually, we get it from these places:

``` js
jsApiList = jsApiList || options.jsApiList || Object.keys(shareDataConfig)
```

So a detail example as below:

``` js
Vue.use(IcShare, {
    // if you specify authFn, than url is optional
    url: '//path/a/b',
    // optional
    jsApi: ['onMenuShareQQ', ...],
    // optional
    debug: '',
    // optional
    authFn: async () => {
        // http send and get data from server
        const authData = await ajax('....')
        return authData
    },
    // optional
    hideAllMenus: ''
})
```

In a component:

``` js
method: {
    share () {
        this.$enableWechatShare(this.shareDataConfig)
    }
}
```

### `$enableWechatShare(shareDataConfig, jsApiList)`
> In internal, we mounted a method `$enableWechatShare` to `Vue.prototype`, so you can use `this.$enableWechatShare` in pages will be shared.

### `$setWechatShareUrl`
> This api for compatibility with ios platform in some special scenarios. We can only use the url of the first opening a page to auth wechat-jsApi once, if you have redirection scenario, you may use the api to set the first url.

For example: Assuming we have three pages, `list`, `home`, `login`. If you have logined and scan a qrcode of login page than redirect to home page, but your shared page is list page. In this case , you should call `$setWechatShareUrl` in home page as below:

home.vue
``` js
{
    mounted: {
        this.$setWechatShareUrl(window.location.href)
    }
}
```

If redirecting to page will be shared directly, you need call `$enableWechatShare` in that page only.

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