学习敲代码,最重要的是学习的过程。开始到现在很长很长的一段时间,当中每次学习都有收获,而这里在收获的同时写一下博客,或者说是做一下笔记,能帮助自己记得更牢固。同时如果发布在平台上之后,如果有人阅读,说明文章的质量还算可以,作为一个程序员,心里多多少少会有一点成就感,这些显然不是很重要的,却帮助自己有更强的求知欲望,同时很欣慰,它可能帮助到了其他的人。一路走来,既充满艰辛,同时也收获知识,收获快乐。
准备
1.npm 账号
注册 https://www.npmjs.com/
这里会验证邮箱,否则npm publish 的时候,提交不了。
2.ghithhub 代码仓库
npm init
npm init //一路回车 会生成 package.json 设置好 main 作为模块的入口
登陆 npm login
npm login
构建完之后两次提交
1.提交到github.(之前要确认 安装好了node_moudle)这里作为仓库使用,也就说,在使用模块的时候,会从仓库这边下载。
2.publish 到 npm(publish 之前要确认 安装好了node_moudle)
npm publish //提交到npm 版本号要大于上一个(package.json里面的version版本号)
安装
cnpm install layui-totals --save //可以直接使用淘宝源进行安装
或者
npm i layui-totals
使用
const name=require('layui-totals');
name.totals(
delat:4000,//4s time
message:'your message'
);
参考 github 地址:https://github.com/ZhiPengTu/totals ,请参考"version": "1.0.4"
{
"name": "layui-totals",
"version": "1.0.4",
"description": "layui totals",
"main": "index.js",
"bin": {
"king": "./bin/king.js"
},
"dependencies": {
"commander": "^2.9.0",
"express": "^4.14.0",
"fs": "^0.0.2",
"ncp": "^2.0.0",
"jquery": "^3.3.1"
},
"devDependencies": {
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ZhiPengTu/totals.git"
},
"keywords": [
"layui"
],
"author": "zhipengtu",
"license": "ISC",
"bugs": {
"url": "https://github.com/ZhiPengTu/totals/issues"
},
"homepage": "https://github.com/ZhiPengTu/totals#readme"
}
index.js
/**
* _totals
* @function _totals
**/
const $ =require('jquery');
const _totals=function(options){
this.timer=null;
this.options={
delay:3000,
message:'hello layUI!'
}
$.extend(this.options, options);
this.init();
}
_totals.prototype.constructor=_totals;
_totals.prototype.init=function(){
var _this = this;
var totalswrap=document.createElement('div');
totalswrap.className='layui-totals';
var totalsSpan=document.createElement('span');
totalsSpan.innerText=_this.options.message;
totalswrap.appendChild(totalsSpan);
var body=document.getElementsByTagName('body')[0];
body.appendChild(totalswrap);
setTimeout(function(){
body.removeChild(totalswrap);
},_this.options.delay);
};
const totals = function(options){
return new _totals(options);
}
module.exports = {
totals: totals
}
网友评论