1.html
<script data-main="./js/pages/index.js" src="./js/lib/require.js"></script>
2. page/index.js
require.config({
paths: {
jquery: '../lib/jquery-1.12.4.min',
template: '../lib/template-web',
bootstrap: '../bootstrap/js/bootstrap.min',
user: '../utils/user',
config: '../utils/config'
}
});
require(['jquery', 'template', 'bootstrap', 'user'], function ($, template, bootstrap, user) {
})
3. utils/config.js
define(function () {
var BASEURL = 'http://localhost:8000/'
var URLIST = {
admin_login: BASEURL + 'admin/login',
admin_logout: BASEURL + 'admin/logout',
getUser: BASEURL + 'admin/getuser',
article_count: BASEURL + 'admin/article_count',
category_search: BASEURL + 'admin/category_search',
category_delete: BASEURL + 'admin/category_delete',
category_add: BASEURL + 'admin/category_add',
category_edit: BASEURL + 'admin/category_edit',
search: BASEURL + 'admin/search',
article_publish: BASEURL + 'admin/article_publish',
article_delete: BASEURL + 'admin/article_delete',
article_edit: BASEURL + 'admin/article_edit'
};
return URLIST;
})
4.utils/user.js
define(['config'], function (URLIST) {
var user = {
login: function (name, password, callback) {
$.ajax({
url: URLIST.admin_login,
type: 'post',
data: { user_name: name, password },
success: function (res) {
callback(res)
}
})
},
logout: function (callback) {
$.ajax({
url: URLIST.admin_logout,
type: 'post',
success: function (res) {
callback(res)
}
})
}
}
return user
})