zoukankan      html  css  js  c++  java
  • 前端MVC学习——模块发开发、seajs学习

      这份学习链接已经足够了:http://seajs.org/docs/#intro

      我假设你至少已经浏览过上述链接文档、并且掌握了基本的seajs基础知识~

      手把手教你创建helloworld~

      HelloWorld

      程序员嘛,难免有helloworld情结~

      平台:win7、chrome

      ① 创建helloworld文件夹

      ② 在helloworld文件夹下,创建index.html、style.css、init.js、data.js、test-export.js、还有一个 lib 文件夹

      ③ 将网上download来的sea.js和jquery-1.10.2.min.js放在由第②步创建的 lib 文件夹中

      下面来看看我们在上述创建的文件里放入了什咩代码

      sea.js和jquery-1.10.2.min.js是库文件,理论上不需要我们修改或添加什么,但是这里有一个小细节,因为sea.js专注模块化开发,对于jquery-1.10.2.min.js的库文件引入,我们也需要将jquery-1.10.2.min.js进行模块化,模块化处理很简单——打开jquery-1.10.2.min.js文件,将jquery-1.10.2.min.js所有代码包括在define中,并且返回$.noConflict();

      jquery-1.10.2.min.js 具体如下:

    define(function() {
         
         //jquery-1.10.2.min.js的源码部分
    
         return $.noConflict();
    
    });

      index.html:

    <!doctype html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title>seajs</title>
    	</head>
    	<body>
    		<div id="content">
    			<p class="author"></p>
    			<p class="blog"><a href="#">blog</a></p>
    		</div>
    		
    		<script src="./lib/sea.js"></script>
    		<script>
    			seajs.use("./init");
    		</script>
    		
    	</body>
    </html>

      init.js

    define(function(require,exports,module) {
    	var $ = require('./lib/jquery-1.10.2.min');
    	var data = require('./data');
    	var css =  require('./style.css');
    	var textExport = require('./test-export');
    	
    	$('.author').html(data.author);
    	$('.blog a').attr('href',data.blog);
    	
    	textExport.test();   /在控制台输出hello world
    });

      data.js

    define({
    	"author": '西红柿炒番茄',
    	"blog": 'http://www.cnblogs.com/Iwillknow/'
    });

      style.css

    .author {
    	color: red;
    	font-size: 16px;
    }
    .blog {
    	font-size: 16px;
    }

      test-export.js

    define(function(require,exports,module) {
    	exports.test = function() {
    		console.log("hello wolrd");
    	};
    });

      

  • 相关阅读:
    【Red Hat Linux基础】 磁盘分区详细教程
    分区间统计sql、删除重复数据
    sql 建立索引之前计算区分度
    jvm调优
    最短路径-迷宫类
    comparable and comparator 比较
    刷题之Implement strStr()、Climbing Stairs
    对线程池简单理解
    hash表系列(转)
    对于AVL树和红黑树的理解
  • 原文地址:https://www.cnblogs.com/Iwillknow/p/3728561.html
Copyright © 2011-2022 走看看