>  기사  >  웹 프론트엔드  >  단일 페이지에서 레이페이지가 켜진 경우 해시의 최적화 방법(코드)

단일 페이지에서 레이페이지가 켜진 경우 해시의 최적화 방법(코드)

不言
不言원래의
2018-08-25 15:57:092209검색

이 글의 내용은 단일 페이지에서 레이페이지를 켰을 때의 해시 최적화 방법(코드)에 관한 내용입니다. 필요한 친구들이 참고하시면 도움이 될 것입니다.

단일 페이지를 사용하는 경우 레이아웃 페이지에서 해시를 켜면 이전 해시가 플러시됩니다

해결 방법은 해시 점프 방식과 통화 계산 방식을 조정하는 것입니다

이후 해시는 다음과 같습니다 # /data/tiebaluntan#!page=98

수정할 수 있는 곳은

laypage.js의

//渲染分页
  Class.prototype.render = function(load){
    var that = this
    ,config = that.config
    ,type = that.type()
    ,view = that.view();
    
    if(type === 2){
      config.elem && (config.elem.innerHTML = view);
    } else if(type === 3){
      config.elem.html(view);
    } else {
      if(doc[id](config.elem)){
        doc[id](config.elem).innerHTML = view;
      }
    }
    config.jump && config.jump(config, load);
    
    var elem = doc[id]('layui-laypage-' + config.index);
    that.jump(elem);
    
    if(config.hash && !load){
      // location.hash = '!'+ config.hash +'='+ config.curr;   // 屏蔽掉该行,修改为下一行
      location.hash = location.hash.substr(0,location.hash.indexOf("#!")==-1 ? 99999:location.hash.indexOf("#!")) + '#!'+ config.hash +'='+ config.curr;
    }
    
    that.skip(elem);
  };

입니다. 다른 하나는 페이지 렌더링의 통화 계산입니다.

//开启HASH
        laypage.render({
            elem: 'test-laypage-demo5'
            ,count: 500
            //,curr: location.hash.replace('#!fenye=', '') //获取hash值为fenye的当前页
            ,curr: location.hash.indexOf("#!")==-1 ? "" : location.hash.substr(location.hash.indexOf("#!"),).replace('#!fenye=', '')//获取hash值为fenye的当前页
            ,hash: 'fenye' //自定义hash值
        });

관련 권장 사항:

layui 기반 무한 조인트 선택기 구현(코드 포함)

layui 형식의 동적 렌더링과 vue.js 간의 충돌 해결(코드 포함)

위 내용은 단일 페이지에서 레이페이지가 켜진 경우 해시의 최적화 방법(코드)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.