NodeJS background

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed, up to tertiary niche: Reverse rest of his life, except you have https://blog.csdn.net/qq_36232611/article/details/90655841

NodeJS background

Background:
1.PHP
2.Java
3.Python

Advantages
1. Performance
2. JS station with easy front
3.NodeJS facilitate distal Learning

https://nodejs.org/en/

image.png

image.png

image.png

1. Switch drive letter E:
2. change the directory name directory cd
3. The program execution node xxx.js

const http = require('http');

http.createServer(function(req, res){
 // 前台响应
 res.write("dashucoding");
 res.end();
});

// 监听
// 端口
server.listen(123);

nodeJS-- server

http-- protocol
REQUEST request
response in response to

image.png

File operations: FS - File System
HTTP - module

Asynchronous vs Synchronous
Asynchronous - Multiple operations can be carried out at the same time, the previous operation did not finish up, can begin after a
sync - one at a time

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

class buffer for storing a binary data buffer
settimeout is time to perform a function for designating a specific function, method designated after the current time from the number of milliseconds
performed cleartimeout function for canceling the function specified in the function 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

Simple small program to achieve double-click event

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

Console, global scope, global variables and functions, events, and event handling mechanism ring mechanism, how to use the debugging tools provided in the framework node.js.


Please thumbs up! Because your encouragement is the greatest power of my writing!

No public official micro letter

Blowing force exchange group: 711,613,774

Blowing force exchange group

Guess you like

Origin blog.csdn.net/qq_36232611/article/details/90655841