Git Product home page Git Product logo

vue-mintui-demo's Introduction

vue-mintUI-demo

利用vue2、mockjs实现前后分离,开发时vue-cli proxyTable 可以解决开发环境的跨域问题,所以针对没有接口数据时采用mockjs方法,有接口时采用修改vue-cli的config文件里index.js的参数proxyTable来开发。

UI采用的是Mint UI,基于 Vue.js 的移动端组件库

要想统一处理所有http请求和响应,就得用上 axios 的拦截器。通过配置http response inteceptor,当后端接口返回-555 (未授权),让用户重新登录。

axios.interceptors.request.use(function (config) {
    return config;
}, function (error) {
    return Promise.reject(error);
});

//请求完成
axios.interceptors.response.use(function (response) {
    if(response.data.code == -555){
        //未登录
        router.replace({
            path: 'login',
            query: {path: router.currentRoute.fullPath.slice(1)}
        })
    }
    return response;
}, function (error) {
    return Promise.reject(error);
});

通过上面这两步,就可以在前端实现登录拦截了。登出功能也就很简单,只需要把当前token清除,再跳转到首页即可。

如果对您有帮助,您可以点右上角 "Star" 支持一下 谢谢! ^_^

说明

因该例子是以公司项目开发的,并没完全做完,所以仅提供学习参考。

技术栈

vue

vue-router

axios

mockjs

webpack

执行命令

通过npm安装本地服务第三方依赖模块(需要已安装Node.js),使用npm安装依赖模块可能会很慢,建议换成cnpm

npm install -g cnpm --registry=http://registry.npm.taobao.org

cnpm install

npm run dev

npm run build

vue-mintui-demo's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.