后台:
1.PHP
2.Java
3.Python
优势
1. 性能
2. 跟前台 JS 配合方便
3.Node.JS 便于前端学习
https://nodejs.org/en/
image.PNG
image.PNG
image.PNG
1. 切换盘符 e:
2. 改变目录 cd 目录名
3. 执行程序 node xxx.JS
- const http = require('http');
- http.createServer(function(req, res){
- // 前台响应
- res.write("dashucoding");
- res.end();
- });
- // 监听
- // 端口
- server.listen(123);
Node.JS-- 服务器
http-- 协议
request 请求
response 响应
image.PNG
文件操作: fs--File System
http-- 模块
异步 vs 同步
异步 -- 多个操作可以同时进行, 前一次的操作没完事, 后一次也能开始
同步 -- 一次一个
- const fs=require('fs');
- // readFile(文件名, 回调函数)
- readFile(文件名, function (err, data){})
- writeFile(文件名, 内容, function (err){})
- oBtn.onclick=function (){
- alert('a');
- };
- alert('b');
image.PNG
image.PNG
image.PNG
- const http=require('http');
- const fs=require('fs');
- var server=http.createServer(function (req, res){
- //req.url=>'/index.html'
- // 读取 =>'./www/index.html'
- // './www'+req.url
- var file_name='./www'+req.url;
- fs.readFile(file_name, function (err, data){
- if(err){
- res.write('404');
- }else{
- res.write(data);
- }
- res.end();
- });
- });
- server.listen(8080);
- const fs=require('fs');
- //writeFile(文件名, 内容, 回调)
- fs.writeFile("bbb.txt", "dda", function (err){
- console.log(err);
- });
- const fs=require('fs');
- //readFile(文件名, 回调函数)
- fs.readFile('aaa.txt', function (err, data){
- if(err){
- console.log('读取失败');
- }else{
- console.log(data.toString());
- }
- });
- //fs.writeFile
buffer 类用于二进制数据的存储提供一个缓存区
settimeout 函数用于指定时间到达执行一个指定函数, 指定方法为从当前时刻之后多少毫秒
cleartimeout 函数用于取消在 settimeout 函数内指定的函数的执行
- var http = require('http');
- http.createServer(function(req,res){
- res.writeHead(200, {
- 'Content-Type':'text/html'
- });
- res.write('<head><meta charset="utf-8"/></head>');
- res.end('你好 \ n');
- }).listen(1234,"127.0.0.1");
- var http=require('http');
- http.createServer(function(req,res){
- // 回调函数中的代码
- })
image.PNG
- // 一行
- white-space: nowrap;
- text-overflow: ellipsis;
- overflow: hidden;
- Word-break: break-all;
- // 两行
- text-overflow: -o-ellipsis-lastline;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- line-clamp: 2;
- -webkit-box-orient: vertical;
image.PNG
image.PNG
小程序简单实现双击事件
- data = {
- tabBar: [],
- // recommendList: [],
- floorList: [],
- banners: [],
- currentIndex: 1,
- canGetCoupon: false,
- // 触摸开始时间
- touchStartTime: 0,
- // 触摸结束时间
- touchEndTime: 0,
- // 最后一次单击事件点击发生时间
- lastTapTime: 0
- }
- getCoupon: function (e) {
- let that = this
- if (that.touchEndTime - that.touchStartTime <350) {
- // 当前点击的时间
- let currentTime = e.timeStamp
- let lastTapTime = that.lastTapTime
- // 更新最后一次点击时间
- that.lastTapTime = currentTime
- // 如果两次点击时间在 300 毫秒内, 则认为是双击事件
- if (currentTime - lastTapTime < 300) {
- // 成功触发双击事件时, 取消单击事件的执行
- // clearTimeout(that.lastTapTimeoutFunc)
- getCoupon({}).then(res => {
- this.canGetCoupon = false
- })
- wx.showToast({
- title: '优惠券领取成功',
- duration: 3000
- })
- }
- }
- doubleClick(e){
- //e.timeStamp: 当前点击时的毫秒数;
- // this.touchStartTime: 储存上一次点击时的毫秒数, 默认 0
- if (e.timeStamp - this.touchStartTime <300){
双击, 进入
- }
- this.touchStartTime = e.timeStamp;
单击
- }
- /*
- if ((e.timeStamp - this.touchStartTime) < 100) {
- getCoupon({}).then(res => {
- this.canGetCoupon = false
- })
- wx.showToast({
- title: '领取成功',
- icon: 'none',
- duration: 3000
- })
- }
- this.touchStartTime = e.timeStamp
- */
- // 触摸开始时间
- touchStartTime: 0,
- // 触摸结束时间
- touchEndTime: 0,
- // 最后一次单击事件点击发生时间
- lastTapTime: 0,
- // 单击事件点击后要触发的函数
- lastTapTimeoutFunc: null,
- /// 双击
- 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
- })
- }
- }
- },
image.PNG
image.PNG
image.PNG
image.PNG
image.PNG
image.PNG
image.PNG
image.PNG
image.PNG
image.PNG
image.PNG
image.PNG
image.PNG
image.PNG
image.PNG
控制台, 全局作用域, 全局变量和全局函数, 事件处理机制以及事件环机制, 怎么使用 node.JS 框架中提供的调试工具.
请点赞! 因为你的鼓励是我写作的最大动力!
官方微信公众号
吹逼交流群: 711613774
吹逼交流群
来源: http://www.jianshu.com/p/5028a549d186