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

dbappsecurity-auth-vue

v1.0.8

Published

axios lister

Downloads

1

Readme

dbappsecurity-auth-vue

针对Vue项目设计的一个基于Vuex Store原理开发的统一登录组件,该组件基于 axios模块,使用vue-resource则无效。就是说ajax使用的是axios的请求方式。

使用方法

  • npm install dbappsecurity-auth-vue

  • 首先在main.js中需要引入 import authStore from 'dbappsecurity-auth-vue',在main.js中需要加入以下代码:

  import authStore from 'dbappsecurity-auth-vue'
  var axios = authStore.axios;
  var store = authStore.store;
  //参数设置,参数不设置则为默认的标题和数据
  store.state.titleName = ''; //网站标题
  store.state.logoUrl = 'http://xxxx.png'; //网站logo图片
  // 将axios挂载到prototype上,在组件中可以直接使用this.axios访问
  Vue.prototype.axios = axios;
  /* eslint-disable no-new */
  new Vue({
    el: '#app',
    router,
    axios,
    store,
    render: (h) => h(App)
  })
  • 其次在router中index.js中需要引入 import authStore from 'dbappsecurity-auth-vue',在inex.js中需要加入以下代码:
  import authStore from 'dbappsecurity-auth-vue'
  var store = authStore.store;
  // 页面刷新时,重新赋值token
  if (window.localStorage.getItem('token') && window.localStorage.getItem('token') != 'undefined') {
      store.commit(authStore.LOGIN, window.localStorage.getItem('token'))
  }
  //过滤路由,如果进入该路由需要登录验证,在配置该路由的时候只需添加
  //meta: {requireAuth: true},不需要验证的设为false
  router.beforeEach((to, from, next) => {
    if (to.matched.some(r => r.meta.requireAuth)) {
        if (to.query.token && to.query.token != 'undefined') {
          store.commit(authStore.LOGIN, to.query.token);
          next(to.path);
        } else if (store.state.token) {
          next();
        } else {
           //此处注意路由没有使用hash的就是使用的module是history的模式。需要添加type=j的参数
          location.href = authStore.URL + '?from=' + encodeURIComponent(location.href) + '&title='+ encodeURIComponent(store.state.titleName) + '&logoUrl=' + encodeURIComponent(store.state.logoUrl);
        }
    } else {
        next();
    }
  })
  • 统一退出 调用方法 this.$store.commit('SIGNOUT') //此处注意路由没有使用hash的就是使用的module是history的模式。需要添加type=j的参数 location.href = authStore.URL + '?from=' + encodeURIComponent(location.href) + '&title='+ encodeURIComponent(store.state.titleName) + '&logoUrl=' + encodeURIComponent(store.state.logoUrl);