Loader 使用示例¶
Loader 使用示例¶
包配置
KISSY.config({ packages:[ { name:"my", //包名 tag:"20110323",//时间戳, 添加在动态脚本路径后面, 用于更新包内模块代码 path:"./", //包对应路径, 相对路径指相对于当前页面路径 charset:"gbk" //包里模块文件编码格式 } ] });定义模块
被依赖模块 my dep
KISSY.add(function () { alert("my/dep loaded"); return "my/dep called"; });主模块 my mod
KISSY.add(function(S,Dep){ alert(Dep); alert("my/mod loaded"); return 'my/mod called'; },{ requires:["./dep","./mod.css"] //相对于当前模块js 定位 });使用模块
KISSY.one("#k12").on("click",function(){ KISSY.use("my/mod",function(S,Mod){ alert(Mod); }); });
Note
这里仅用于演示,生产环境下请用有意义的包名