Blogger Information
Blog 5
fans 0
comment 0
visits 5357
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
终于搞懂了layui的模块化
5AiPHP
Original
655 people have browsed it
这是index.js文件内容:
layui.define(['form','layer','element'],function(exports){
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var element = layui.element;
 
    var objList = {
        ajax:function(filter,url){
            form.on(filter,function(data){
                $.ajax({
                    url:url,
                    data:data.field,
                    type:'post',
                    dataType:'json',
                    success:function(result){
                        if(result.status==0){
                            layer.msg(result.msg);
                        }
                    }
                });
                return false;
            });
        },
        hello:function(str){
            $('#btn').click(function(){
                layer.msg(str);
            });
        }
    };
    exports('index',objList);
});
这是index.html的内容:
    <script>
        layui.config({
            base: '/static/js/'
        }).use('index', function () {
            var index = layui.index;
            index.ajax('submit(formDemo)',"{:url('index')}");
            // index.hello('Hello World');
        });
    </script>

接收数据我是用TP框架测试的,确实模块化后代码通用性高了,记下来不会忘记了!

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post