前端技术前沿9
2023-09-11 14:16:52 时间
Node.js使用Module模块去划分不同的功能,以简化应用的开发。
var myModule = require('./myModule.js');
将某些方法和变量暴露到模块外,可以使用exports对象去实现。
安装
Linux 下 Node.js的安装
sudo apt-get update
sudo apt-get install node
或者:
sudo aptitude update
sudo aptitude install node
var http = require('http');
server = http.createServer(function (req, res) {
res.writeHeader(200, {"Content-Type": "text/plain"});
res.end("Hello");
});
server.listen(8000);
console.log("httpd start @8000");
console.log("Hello World");
node helloworld.js
Node.js 安装配置
引入required模块
创建服务器
接收请求与响应请求
步骤一、引入required模块
var http = require("http");
步骤一、创建服务器
使用http.createServer()方法创建服务器,并使用listen方法绑定8888端口。 函数通过request, response参数来接收和响应数据。
双击
// 触摸开始时间
touchStartTime: 0,
// 触摸结束时间
touchEndTime: 0,
// 最后一次单击事件点击发生时间
lastTapTime: 0,
// 单击事件点击后要触发的函数
lastTapTimeoutFunc: null,
/// 按钮触摸开始触发的事件
touchStart: function(e) {
this.touchStartTime = e.timeStamp
},
/// 按钮触摸结束触发的事件
touchEnd: function(e) {
this.touchEndTime = e.timeStamp
},
/// 单击
tap: function(e) {
var that = this
wx.showModal({
title: '提示',
content: '单击事件被触发',
showCancel: false
})
},
/// 双击
doubleTap: function(e) {
var that = this
// 控制点击事件在350ms内触发,加这层判断是为了防止长按时会触发点击事件
if (that.touchEndTime - that.touchStartTime < 350) {
// 当前点击的时间
var currentTime = e.timeStamp
var lastTapTime = that.lastTapTime
// 更新最后一次点击时间
that.lastTapTime = currentTime
// 如果两次点击时间在300毫秒内,则认为是双击事件
if (currentTime - lastTapTime < 300) {
console.log("double tap")
// 成功触发双击事件时,取消单击事件的执行
clearTimeout(that.lastTapTimeoutFunc);
wx.showModal({
title: '提示',
content: '双击事件被触发',
showCancel: false
})
}
}
},
单击、双击和长按同时存在的实现:
/// 长按
longTap: function(e) {
console.log("long tap")
wx.showModal({
title: '提示',
content: '长按事件被触发',
showCancel: false
})
},
/// 单击、双击
multipleTap: function(e) {
var that = this
// 控制点击事件在350ms内触发,加这层判断是为了防止长按时会触发点击事件
if (that.touchEndTime - that.touchStartTime < 350) {
// 当前点击的时间
var currentTime = e.timeStamp
var lastTapTime = that.lastTapTime
// 更新最后一次点击时间
that.lastTapTime = currentTime
// 如果两次点击时间在300毫秒内,则认为是双击事件
if (currentTime - lastTapTime < 300) {
console.log("double tap")
// 成功触发双击事件时,取消单击事件的执行
clearTimeout(that.lastTapTimeoutFunc);
wx.showModal({
title: '提示',
content: '双击事件被触发',
showCancel: false
})
} else {
// 单击事件延时300毫秒执行,这和最初的浏览器的点击300ms延时有点像。
that.lastTapTimeoutFunc = setTimeout(function () {
console.log("tap")
wx.showModal({
title: '提示',
content: '单击事件被触发',
showCancel: false
})
}, 300);
}
}
},
var http = require('http');
http.createServer(function (request, response) {
// 发送 HTTP 头部
// HTTP 状态值: 200 : OK
// 内容类型: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// 发送响应数据 "Hello World"
response.end('Hello World\n');
}).listen(8888);
// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');
请点赞!因为你的鼓励是我写作的最大动力!
吹逼交流群:711613774
相关文章
- 【华为云技术分享】三大前端技术(React,Vue,Angular)探密(下)
- 【华为云技术分享】云图说 | 容器交付流水线ContainerOps,助力企业容器化转型
- 【华为云技术分享】一统江湖大前端DOClever—你的Postman有点Low
- 【华为云技术分享】大前端的自动化工厂— babel
- 前端技术
- 2020 有哪些不容错过的前端技术趋势?
- 未来物联网、人工智能无法迈过的技术是什么
- [破解] DRM-内容数据版权加密保护技术学习(中):License预发放实现
- 微服务实践:全栈小团队“洪荒之力”改造阿里服务CRM技术体系
- Android版OpenCV图像处理技术亲自验证[二十一]之目标跟踪--CamShift(附源码)
- 如何查看CRM WebUI,C4C和Hybris里的页面技术信息
- Atitit 前端算法技术体系总结 目录 1. 3. Ui方面的算法 32 3.1. 软键盘算法 计算软键盘上下左右按键位置 32 3.2. Sprire生成随机位置算法 随机数算法 3
- Atitit 面试技术点最小化问题法总结 目录 1. Web 前端1 1.1. Jq 常用操作哪些??1 1.2. 查询后如何绑定后端数据到表格2 1.3. 提交后怎么接受表单数据2 2.
- Atitit.cto 与技术总监的区别
- 蚂蚁金服安全产品技术资深总监冯春培:用生态的力量解决安全生态的问题
- Go语言逆向技术:恢复函数名称算法
- 【华为云技术分享】三大前端技术(React,Vue,Angular)探密(上)
- 【华为云技术分享】【一统江湖的大前端(8)】matter.js 经典物理
- 【华为云技术分享】【一统江湖的大前端】PPT制作库impress.js
- 交易系统TMF2.0技术揭秘:跳开 DDD 和中台概念看阿里巴巴交易平台的问题及解决思路...
- 004-搭建框架-实现AOP机制【一】代理技术
- 软件测试技术之如何编写测试用例(5)
- 5年前端老司机:浅谈web前端开发技术点
- 2021年最适合测试同学学习的技术
- IT技术干货|软件测试任务分配
- 挖矿木马简要技术分析
- Py:python利用easygui实现最简单GUI带你学习区块链技术的发展和由来