npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

v-wechat-auth

v1.0.0

Published

wechat auth plugin for vue 2.0

Downloads

14

Readme

v-wechat-auth

npm vue2

vue 2.0 微信网页授权插件

安装

npm

npm install --save v-wechat-auth
import Vue from 'vue'
import VWechatAuth from 'v-wechat-auth'

通过 script 标签

<!-- 在 Vue 之后 -->
<!-- 从本地文件 -->
<script src="v-wechat-auth/dist/v-wechat-auth.min.js"></script>

<!-- 从 CDN -->
<script src="https://unpkg.com/v-wechat-auth"></script>

使用

初始化

Vue.use(VWechatAuth)

// 必须在 root 实例上注入 wechatAuth
new Vue({
  el: '#app',
  ...,
  wechatAuth: new VWechatAuth({
    appId: 'your wechat appid',
    scope: 'snsapi_base or snsapi_userinfo'
    authorize () {
      return axios.get('your backend api here', { params: { code: code } })
        .then(function (res) {
          var data = (res && res.data) || {} // response data should at least contain openid
          return data
        })
    }
  })
})

调用

this.$wechatAuth.authorize()

运行例子

  1. examples 文件夹中的 config.example.js 重命名为 config.js

  2. 修改 config.js, 填入微信 appid 和 scope, 并在 authorize 方法中调用后端接口获取用户信息,并将用户信息返回

  3. 修改 host 文件,将微信授权域名映射为 localhost

  4. 运行 npm run example

  5. 在微信开发者工具中访问 授权域名/examples/index.html(因为修改了host,这时访问的实际上是本地)

  6. 能显示当前用户的 openid

openid

options

| 属性 | 类型 | 必输 | 默认 | 说明 | |-------|-------|-------|-------|-------| | autoRedirect | boolean | 否 | true | 当 url 中不包含 code 参数或返回结果中不包含openid时,是否自动重定向到微信授权url | | appId | string | 是 | | 微信 appid | | scope | string | 是 | | 微信 scope, snsapi_basesnsapi_userinfo | | state | string | 否 | '' | 微信 state | | authorize | function | 是 | | ajax 请求调用后端接口获取微信用户信息 | ssr | boolean | 否 | | 是否使用服务端渲染,尚未实现 |

VWechatAuth 实例

| 属性 | 说明 | |------|------| | user | 当获取用户信息成功后,存储了用户的信息,否则为一个空对象 |

| 方法 | 参数 | 返回 | 说明 | |------|------|-------|------| | authorize | onSuccess,执行成功的回调函数 onFail,执行失败的回调函数 | Promise | 授权获取用户信息,支持回调函数 和 Promise

License

MIT