仓库地址:https://gitee.com/littleboyck/front.git
目录所在位置:router文件夹
index.html的<body>中
<div id="app">div>
view文件夹中新建layout.html
<div class="layout-fluid">
<div><a r-link="#/home">首页a>div>
<div><a r-link="#/button">按钮组件a>div>
<div><a r-link="#/form">表单组件a>div>
<div><a r-link="#/bdage">徽章组件a>div>
<div id="app-body" class="layadmin-tabspage-none">div>
div>
class Router{
constructor(options){
//缓存route数据信息
this.routes = {};
this.options = options;
this.ready();
}
//伪数组转为真数值
static arrayLike(arrLike){
return Array.from ? Array.from(arrLike) : Array.prototype.slice.call(arrLike);
}
static isLikeArr(el){
return typeof el == 'object' && !(el instanceof Array) && el.length>0 ? true : false;
}
static isDOM(el){
return el.nodeType == (Node.ELEMENT_NODE||Node.DOCUMENT_NODE) || Router.isLikeArr(el);
}
static getEl(selector){
if(selector.nodeType != (Node.ELEMENT_NODE||Node.DOCUMENT_NODE)){
if(/^#[^#\s\b]+$/.test(selector)){
selector = document.querySelector(selector)
}else{
selector = document.querySelectorAll(selector)
}
}
return selector;
}
static animationEnd(ele,sucHandle){
//1、获取动画名
let animateName = function(){
const animation = {
'animation': 'animationend',
'OAnimation': 'oAnimationEnd',
'MozAnimation': 'mozAnimationEnd',
'WebkitAnimation': 'webkitAnimationEnd'
}
const animateName = (function(el) {
for (let t in animation) {
if (el.style[t] !== undefined) {
return animation[t];
}
}
})(document.createElement('div'));
return animateName;
}();
//2、给ele绑定动画结束的回调
const animateEndEventListener = function(sucHandle){
//在每次transitionEnd的事件后执行该函数
const handleAniEnd = function(e){
ele.removeEventListener(animateName,handleAniEnd);
sucHandle.call(this,e,ele);
};
ele.addEventListener(animateName,handleAniEnd,false);
}
animateName && animateEndEventListener(sucHandle)
}
static evtListener(el,event,handle){
el = Router.isDOM(el) ? [...el] : [el];
el.forEach(el=>el.addEventListener(event,handle));
}
static removeListener(el,event,handle){
el = Router.isDOM(el) ? [...el] : [el];
el.forEach(el=>el.removeEventListener(event,handle));
}
static isHash(val){
return /#[^#.]+/.test(val)
}
static evalScripts(text){
let script
,scripts = []
, regexp = /