@msbfe/login-js

1.0.9 • Public • Published

@msb/login-js

nuxt2接入示例

// src/plugins/login.client.js
import Vue from 'vue'
import LoginPlugin from '@msbfe/login-js'
import '@msbfe/login-js/dist/style.css'

export default () => {
    Vue.prototype.$login = function(callback) {
        if (!localStorage.getItem("token")) {
            const loginInstance = LoginPlugin.getInstance({
                env: process.env.EXEC_ENV,
                success: (data) => {
                    // 登录后统一处理方法(储存token,获取用户信息等)
                    // ....

                    loginInstance.close()

                    if (typeof callback === 'function') {
                        callback(data)
                    }
                },
            })
            loginInstance.open()
        } else if (typeof callback === 'function') {
            callback()
        }
    }
}

// nuxt.config.js
plugins: [{ src: "~/plugins/login.client", ssr: false }]

// src/pages/xxx.vue
function onClick = () => {
  this.$login({
    // 登录鉴权后执行某些操作
    // ....
  })
}

Readme

Keywords

none

Package Sidebar

Install

npm i @msbfe/login-js

Weekly Downloads

0

Version

1.0.9

License

none

Unpacked Size

20.9 kB

Total Files

5

Last publish

Collaborators

  • cwl_ch
  • wang92