Navigo

A simple minimalistic JavaScript router with a fallback for older browsers.
一个简单的极简主义的JavaScript路由器Navigo

import Navigo from '../../common/navigo';
import {initMyOrder} from './myOrder';
import {getUserInfo} from './myPersonalCenter';

$(function () {
    let onMyOrder=function(){
        $("#myOrder").fadeIn();
        $("#myPersonalCenter").fadeOut();
        initMyOrder();
    };
    let onMyPersonalCenter=function(){
        $("#myOrder").fadeOut();
        $("#myPersonalCenter").fadeIn();
        getUserInfo();
    };
    //
    let changeClass=function(){
        $(".uc-nav-list li").off('click').on('click',function () {
            $(".uc-nav-list li").removeClass('active');
            $(this).addClass('active')
        })
    }

    let router = new Navigo(null, true, '#');

    router.on({
            '/order': function () {
                onMyOrder();
            },
            '/commentOrder': function () {
                //onCommentOrder();
            },
            '/': function () {
                onMyOrder();
            }
        })
        .resolve();
        changeClass();

});

可实现侧栏菜单,点击不刷新

//myPersonalCenter
import {getUserInformation} from '../../controller/user';
import {getOrderList} from '../../controller/order';
export function getUserInfo(){
    getUserInformation().then((data)=>{
        $(".username").html(data['userName']);
        $(".tel").html(data['mobile']);

    }).catch(function (err) {
        console.log(err)
    });
}

你可能感兴趣的:(Navigo)