Coder Social home page Coder Social logo

mpvue-process's Introduction

mpvue-process

登录验证
1. mpvue页面登录判断

配置apiBaseUrl,登录页,需要登录才能查看的页面:
config = {
  baseUrl: 'https://www.xxxxxxx.com/',
  loginPage: '/pages/login/main',
  pageAuth: [
    '/pages/xxxx/main',
    '/pages/yyyy/main'
  ]
}
在main.js中添加
import MpvueProcess from 'mpvue-process'
Vue.use(MpvueProcess, config)
2. 使用
页面级登录判断:
this.navigateTo()替换mpvue.navigateTo()方法,如果页面需要登录则会先跳转到登录页

按钮级登录判断:
if(!this.isAuthed){
    没登录情况
} else{
    登录请求
}

3.登录后保存token
this.setStore('token',xxxxxx)
请求封装
需要转loading的
const res = await this.request('api1', 'GET', {}, true)
不需要转loading的
const res = await this.request('api2', 'GET', {})
this.request('api3', 'GET', {}).then(resp=>{console.log(resp)})
自定义header
const res = await this.request('api2', 'GET', {}, false, headers)
本请求会自动封装如下header
{'Content-Type': 'application/json', 'Authorization': 'Token ' + getStore('token')}
缓存
this.setStore('key',value,1*24*60*60) // 缓存一天,默认2天
this.getStore('key')

mpvue-process's People

Contributors

joindn avatar

Stargazers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.