>  기사  >  백엔드 개발  >  引用requirejs,网速不好时,会提示require is not defined

引用requirejs,网速不好时,会提示require is not defined

WBOY
WBOY원래의
2016-06-06 20:32:303782검색

有的时候,可以输出'aaa'

但有的时候,会// Uncaught ReferenceError: require is not defined
图片描述
引用requirejs,网速不好时,会提示require is not defined

引用requirejs,网速不好时,会提示require is not defined


<code>require.config({
        baseUrl: '<?php echo $this->config->base_url(); ?>',
        paths: {
            jquery: 'assets/js/jquery.min',
            bootstrap: 'assets/js/bootstrap.min',
            fastclick: 'assets/js/fastclick',
            swal: 'assets/js/sweet-alert',
            bootstrapSelect: 'assets/js/bootstrap-select.min',
            ueditorConfig: 'assets/js/ueditor/ueditor.config',
            ueditor: 'assets/js/ueditor/ueditor.all.min',
            domReady: 'assets/js/domReady'
        },
        shim: {
            bootstrap: {
            deps: ['jquery'],
            exports: 'bootstrap'
            }
        },
        urlArgs: 'v=' + (new Date()).getTime()
    });


    require(['domReady'],function(domReady){
        domReady(function(){
            console.log('aaa');
        });
    });
    // Uncaught ReferenceError: require is not defined
</code>

回复内容:

有的时候,可以输出'aaa'

但有的时候,会// Uncaught ReferenceError: require is not defined
图片描述
引用requirejs,网速不好时,会提示require is not defined

引用requirejs,网速不好时,会提示require is not defined


<code>require.config({
        baseUrl: '<?php echo $this->config->base_url(); ?>',
        paths: {
            jquery: 'assets/js/jquery.min',
            bootstrap: 'assets/js/bootstrap.min',
            fastclick: 'assets/js/fastclick',
            swal: 'assets/js/sweet-alert',
            bootstrapSelect: 'assets/js/bootstrap-select.min',
            ueditorConfig: 'assets/js/ueditor/ueditor.config',
            ueditor: 'assets/js/ueditor/ueditor.all.min',
            domReady: 'assets/js/domReady'
        },
        shim: {
            bootstrap: {
            deps: ['jquery'],
            exports: 'bootstrap'
            }
        },
        urlArgs: 'v=' + (new Date()).getTime()
    });


    require(['domReady'],function(domReady){
        domReady(function(){
            console.log('aaa');
        });
    });
    // Uncaught ReferenceError: require is not defined
</code>

其实一般大家在生产环境里的时候是不会引用requirejs,上线的都是打包好的。

引入requirejs去掉asyn和defer属性

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