前言

最近学习了一下node.js相关的内容,在这里初步做个小总结,说实话关于本篇博客的相关内容,自己很久之前就已经有过学习,但是你懂的,“好记性不如烂笔筒”,学过的东西不做笔记的话,很容易就会忘记的一干二净,往往的结果就是自己又要重头开始学习,这是一个非常痛苦的过程。没有办法,为了重新捡起自己曾经学过的内容,决定写下这篇博客来回顾自己所学的知识。

本章目标

Node.js后端

  • 学会使用node.js操作MySQL实现简单的增删查改
  • 学会使用RESTful风格定义接口

前端

  • 学会使用vue2整合Ajax
  • 学会使用vue2整合axios

项目搭建

MySQL数据库

数据库脚本

创建鲜花信息表,添加鲜花编号,鲜花名称,鲜花价格,鲜花用途,鲜花花材,鲜花花语等字段。在这里我们就直接使用SQL脚本来创建数据表和添加一些测试数据。

CREATE table flowerinfo
(
fid BIGINT auto_increment PRIMARY key not NULL COMMENT"编号",
fname varchar(20) not null COMMENT"名称",
fprice DECIMAL(16,2) COMMENT"价格",
fsituation varchar(20) not null COMMENT"使用节日",
fuse varchar(20) not null COMMENT"鲜花用途",
fhc varchar(20) not null COMMENT"鲜花花材",
fword varchar(50) COMMENT"花语"
)COMMENT"鲜花信息表" INSERT into flowerinfo(fname,fprice,fhc,fuse,fsituation,fword)
VALUES("一生一世",200,"玫瑰,香槟","爱情鲜花","情人节","你是我一生一世唯一的爱人,我会好好珍惜你"),
("祝福你",300,"玫瑰,香槟","爱情鲜花","情人节,母亲节,父亲节","我把我最真诚的祝福送给你,祝你天天开心"),
("一生一世",200,"玫瑰,香槟","爱情鲜花","情人节","你是我一生一世唯一的爱人,我会好好珍惜你"),
("祝福你",300,"玫瑰,香槟","爱情鲜花","情人节,母亲节,父亲节","我把我最真诚的祝福送给你,祝你天天开心")

结果:

Node.js后端项目搭建

1、搭建node.js项目

搭建node.js项目的过程我就直接省略了,具体如何搭建node.js项目大家可以自行百度或者后期我会添加相关内容的博客方便大家学习。搭建好的项目结构如下:

2、安装mysql依赖

既然我们需要操作mysql,那么我们肯定需要安装相关的依赖,在这里介绍三种方法安装mysql依赖。

方式一:

cnpm install mysql  //使用淘宝镜像依赖mysql

方式二:

npm install mysql --save    // 当前项目安装mysql依赖

方式三:

npm install mysql -g    //全局安装mysql依赖

选择任意以上一种方法安装都可以,安装完成之后,我们确认一下是否真的安装成功,找到目录node_modules,这里是查看我们安装的所有依赖,可以看到mysql依赖成功了。

3、编写RESTful风格的接口

找到目录结构routes,新建flowerRouter.js文件。目录结构如下:

一、建立node.js和mysql数据库的连接

let express=require('express'); //  引入express依赖
let mysql=require('mysql') // 引入mysql依赖
let router=express.Router();
let connection=mysql.createConnection({
host: 'localhost', //主机名
user:'root', //账号
password:'123456', //密码
database:'flower' //连接的数据库名称
});
connection.connect(); //建立连接

第一步的话主要式建立起node.js和mysql之间的桥梁。部分参数说明如下:

参数 描述
host 主机地址 (默认:localhost)
user 用户名
password 密码
port 端口号 (默认:3306)
database 数据库名称
charset 连接字符集(默认:'UTF8_GENERAL_CI',注意字符集的字母都要大写)
 localAddress  此IP用于TCP连接(可选)
 socketPath  连接到unix域路径,当使用 host 和 port 时会被忽略
 timezone  时区(默认:'local')
 connectTimeout  连接超时(默认:不限制;单位:毫秒)
 stringifyObjects  是否序列化对象
 typeCast  是否将列值转化为本地JavaScript类型值 (默认:true)
 queryFormat  自定义query语句格式化方法
 supportBigNumbers  数据库支持bigint或decimal类型列时,需要设此option为true (默认:false)
 bigNumberStrings  supportBigNumbers和bigNumberStrings启用 强制bigint或decimal列以JavaScript字符串类型返回(默认:false)
 dateStrings  强制timestamp,datetime,data类型以字符串类型返回,而不是JavaScript Date类型(默认:false)
 debug  开启调试(默认:false)
 multipleStatements  是否许一个query中有多个MySQL语句 (默认:false)
 flags  用于修改连接标志
 ssl  使用ssl参数(与crypto.createCredenitals参数格式一至)或一个包含ssl配置文件名称的字符串,目前只捆绑Amazon RDS的配置文件

具体参数信息请前往:https://github.com/mysqljs/mysql

二、添加数据接口和SQL语句

//  添加鲜花信息
router.post('/addFlower',(req,res,next)=>{
let fname=req.body.fname; //名称
let fprice=req.body.fprice;// 价格
let fsituation=req.body.fsituation; //节日
let fuse=req.body.fuse; // 用途
let fhc=req.body.fhc; // 花材
let fword=req.body.fword; //花语
let addsql="insert into flowerinfo(fid,fname,fprice,fsituation,fuse,fhc,fword)values(0,?,?,?,?,?,?)";
let addsqlParams=[fname,fprice,fsituation,fuse,fhc,fword];
connection.query(addsql,addsqlParams,(err,result)=>{
if(err){
throw err;
return;
}
res.send('添加成功!');
})
})

三、修改数据接口和SQL语句

//  修改鲜花信息
router.put('/updateFlower',(req,res,next)=>{
let id=req.body.fid;
let fname=req.body.fname; //名称
let fprice=req.body.fprice;// 价格
let fsituation=req.body.fsituation; //节日
let fuse=req.body.fuse; // 用途
let fhc=req.body.fhc; // 花材
let fword=req.body.fword; //花语
let updatesql='update flowerinfo set fname=?,fprice=?,fsituation=?,fuse=?,fhc=?,fword=? where fid=?';
let updatesqlParams=[fname,fprice,fsituation,fuse,fhc,fword,id]
connection.query(updatesql,updatesqlParams,(err,result)=>{
if (err){
throw err;
return false
}
res.send('修改成功!');
})
})

四、查询全部数据接口和SQL语句

//  查询全部鲜花信息
router.get('/getAllFlower',(req,res,next)=>{
connection.query('select * from flowerinfo',(err,result)=>{
if(err){
throw err;
return;
}
res.send(result);
})
});

五、查询单条数据接口和SQL语句

//  根据鲜花编号查询鲜花信息
router.get('/findFlowerById',(req,res,next)=>{
let id=req.query.id;
let selectsql='select * from flowerinfo where fid=?';
let selctParams=[id];
connection.query(selectsql,selctParams,(err,result)=>{
if (err){
throw err
}
res.send(result);
})
})

六、删除数据接口和SQL语句

//  删除鲜花信息
router.delete('/deleteFlower',(req,res,next)=>{
let id=req.body.id;
let deletesql="delete from flowerinfo where fid=?";
let deletesqlParams=[id];
connection.query(deletesql,deletesqlParams,(err,result)=>{
if(err){
throw err;
return false;
}
res.send('删除成功!');
})
})
module.exports=router;

七、全部代码:

let express=require('express'); //  引入express依赖
let mysql=require('mysql') // 引入mysql依赖
let router=express.Router();
let connection=mysql.createConnection({
host: 'localhost', //主机名
user:'root', //账号
password:'123456', //密码
database:'flower' //连接的数据库名称
});
connection.connect(); //建立连接
// 查询全部鲜花信息
router.get('/getAllFlower',(req,res,next)=>{
connection.query('select * from flowerinfo',(err,result)=>{
if(err){
throw err;
return;
}
res.send(result);
})
});
// 添加鲜花信息
router.post('/addFlower',(req,res,next)=>{
let fname=req.body.fname; //名称
let fprice=req.body.fprice;// 价格
let fsituation=req.body.fsituation; //节日
let fuse=req.body.fuse; // 用途
let fhc=req.body.fhc; // 花材
let fword=req.body.fword; //花语
let addsql="insert into flowerinfo(fid,fname,fprice,fsituation,fuse,fhc,fword)values(0,?,?,?,?,?,?)";
let addsqlParams=[fname,fprice,fsituation,fuse,fhc,fword];
connection.query(addsql,addsqlParams,(err,result)=>{
if(err){
throw err;
return;
}
res.send('添加成功!');
})
})
// 根据鲜花编号查询鲜花信息
router.get('/findFlowerById',(req,res,next)=>{
let id=req.query.id;
let selectsql='select * from flowerinfo where fid=?';
let selctParams=[id];
connection.query(selectsql,selctParams,(err,result)=>{
if (err){
throw err
}
res.send(result);
})
})
// 修改鲜花信息
router.put('/updateFlower',(req,res,next)=>{
let id=req.body.fid;
let fname=req.body.fname; //名称
let fprice=req.body.fprice;// 价格
let fsituation=req.body.fsituation; //节日
let fuse=req.body.fuse; // 用途
let fhc=req.body.fhc; // 花材
let fword=req.body.fword; //花语
let updatesql='update flowerinfo set fname=?,fprice=?,fsituation=?,fuse=?,fhc=?,fword=? where fid=?';
let updatesqlParams=[fname,fprice,fsituation,fuse,fhc,fword,id]
connection.query(updatesql,updatesqlParams,(err,result)=>{
if (err){
throw err;
return false
}
res.send('修改成功!');
})
})
// 删除鲜花信息
router.delete('/deleteFlower',(req,res,next)=>{
let id=req.body.id;
let deletesql="delete from flowerinfo where fid=?";
let deletesqlParams=[id];
connection.query(deletesql,deletesqlParams,(err,result)=>{
if(err){
throw err;
return false;
}
res.send('删除成功!');
})
})
module.exports=router;

这里有个重大的bug,就是我们连接完之后没有关闭连接,这样就会资源的浪费,占用cpu。这里大家可以想办法去解决,由于我们这里是测试的,所以没有设置关闭连接。

注意:结尾一定要写module.exports=router

4、注册router和设置跨域请求

找到目录结构下的app.js文件注册路由和跨域请求设置。

app.js文件代码

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan'); var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var productRouter=require('./routes/product');
var flowerRouter=require('./routes/flowerRouter')
var app = express(); // view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs'); app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// 设置跨域请求
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "content-type");
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By", ' 3.2.1');
res.header("Content-Type", "application/json;charset=utf-8");
if(req.method == "OPTIONS") {
res.send("200");
} else {
next();
}
});
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/product',productRouter);
app.use('/flower',flowerRouter); // catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
}); // error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {}; // render the error page
res.status(err.status || 500);
res.render('error');
}); module.exports = app;

红色标注的表示新增的路由注册和添加的跨域请求。

跨域代码:

//  设置跨域请求
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "content-type");
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By", ' 3.2.1');
res.header("Content-Type", "application/json;charset=utf-8");
if(req.method == "OPTIONS") {
res.send("200");
} else {
next();
}
});

前端

前端方面主要使用两种方法操作数据,一种是ajax,另一种是axios,将所需要用到的插件引入。目录结构如下:

在这里我们引入的vue.js,axios,jQuey,以及新建两个html文件,为了方便命名上已经规定了。接下来就是数据操作了。

vue2整合ajax

一、查询全部鲜花信息

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ajax和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/jquery-3.3.1.min.js"></script>
<script src="javascripts/vue.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息 },
deleteFlower:function (id) { //删除鲜花信息 },
addFlower:function () { // 添加鲜花信息 },
updateFlower:function (id) { // 修改鲜花信息 },
findAllFlower:function () { // 查询全部鲜花信息
$.ajax({
url:'http://localhost:3000/flower/getAllFlower',
type:"GET",
dataType:"json"
}).done((data)=>{
this.flowerArray=data;
})
}
},
}) </script>
</body>
</html>

二、根据条件查询鲜花信息

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ajax和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/jquery-3.3.1.min.js"></script>
<script src="javascripts/vue.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息
this.fid=id;
$.ajax({
url:'http://localhost:3000/flower/findFlowerById',
type:'GET',
data:{id:id}
}).done((data)=>{
this.fname=data[0].fname;
this.fprice=data[0].fprice;
this.fsituation=data[0].fsituation;
this.fuse=data[0].fuse;
this.fhc=data[0].fhc;
this.fword=data[0].fword;
})
},
deleteFlower:function (id) { //删除鲜花信息 },
addFlower:function () { // 添加鲜花信息 },
updateFlower:function (id) { // 修改鲜花信息 },
findAllFlower:function () { // 查询全部鲜花信息
$.ajax({
url:'http://localhost:3000/flower/getAllFlower',
type:"GET",
dataType:"json"
}).done((data)=>{
this.flowerArray=data;
})
}
},
}) </script>
</body>
</html>

三、添加鲜花信息

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ajax和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/jquery-3.3.1.min.js"></script>
<script src="javascripts/vue.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息 },
deleteFlower:function (id) { //删除鲜花信息 },
addFlower:function () { // 添加鲜花信息
$.ajax({
url:'http://localhost:3000/flower/addFlower',
type:'POST',
data:{
fname:this.fname,
fprice:this.fprice,
fsituation:this.fsituation,
fuse:this.fuse,
fhc:this.fhc,
fword:this.fword,
}
}).done((data)=>{
})
},
updateFlower:function (id) { // 修改鲜花信息 },
findAllFlower:function () { // 查询全部鲜花信息
$.ajax({
url:'http://localhost:3000/flower/getAllFlower',
type:"GET",
dataType:"json"
}).done((data)=>{
this.flowerArray=data;
})
}
},
}) </script>
</body>
</html>

四、修改鲜花信息

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ajax和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/jquery-3.3.1.min.js"></script>
<script src="javascripts/vue.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息
this.fid=id;
$.ajax({
url:'http://localhost:3000/flower/findFlowerById',
type:'GET',
data:{id:id}
}).done((data)=>{
this.fname=data[0].fname;
this.fprice=data[0].fprice;
this.fsituation=data[0].fsituation;
this.fuse=data[0].fuse;
this.fhc=data[0].fhc;
this.fword=data[0].fword;
})
},
deleteFlower:function (id) { //删除鲜花信息 },
addFlower:function () { // 添加鲜花信息 },
updateFlower:function (id) { // 修改鲜花信息
$.ajax({
url:'http://localhost:3000/flower/updateFlower',
type:'PUT',
data:{
fid:this.fid,
fname:this.fname,
fprice:this.fprice,
fsituation:this.fsituation,
fuse:this.fuse,
fhc:this.fhc,
fword:this.fword,
},
}).done((data)=>{ })
},
findAllFlower:function () { // 查询全部鲜花信息
$.ajax({
url:'http://localhost:3000/flower/getAllFlower',
type:"GET",
dataType:"json"
}).done((data)=>{
this.flowerArray=data;
})
}
},
}) </script>
</body>
</html>

五、删除鲜花信息

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ajax和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/jquery-3.3.1.min.js"></script>
<script src="javascripts/vue.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息 },
deleteFlower:function (id) { //删除鲜花信息
$.ajax({
url:'http://localhost:3000/flower/deleteFlower',
type:"DELETE",
data:{
id:id
},
}).done((data)=>{ })
},
addFlower:function () { // 添加鲜花信息 },
updateFlower:function (id) { // 修改鲜花信息
},
findAllFlower:function () { // 查询全部鲜花信息
$.ajax({
url:'http://localhost:3000/flower/getAllFlower',
type:"GET",
dataType:"json"
}).done((data)=>{
this.flowerArray=data;
})
}
},
}) </script>
</body>
</html>

六、全部代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ajax和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/jquery-3.3.1.min.js"></script>
<script src="javascripts/vue.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息
this.fid=id;
$.ajax({
url:'http://localhost:3000/flower/findFlowerById',
type:'GET',
data:{id:id}
}).done((data)=>{
this.fname=data[0].fname;
this.fprice=data[0].fprice;
this.fsituation=data[0].fsituation;
this.fuse=data[0].fuse;
this.fhc=data[0].fhc;
this.fword=data[0].fword;
})
},
deleteFlower:function (id) { //删除鲜花信息
$.ajax({
url:'http://localhost:3000/flower/deleteFlower',
type:"DELETE",
data:{
id:id
},
}).done((data)=>{ })
},
addFlower:function () { // 添加鲜花信息
$.ajax({
url:'http://localhost:3000/flower/addFlower',
type:'POST',
data:{
fname:this.fname,
fprice:this.fprice,
fsituation:this.fsituation,
fuse:this.fuse,
fhc:this.fhc,
fword:this.fword,
}
}).done((data)=>{
})
},
updateFlower:function (id) { // 修改鲜花信息
$.ajax({
url:'http://localhost:3000/flower/updateFlower',
type:'PUT',
data:{
fid:this.fid,
fname:this.fname,
fprice:this.fprice,
fsituation:this.fsituation,
fuse:this.fuse,
fhc:this.fhc,
fword:this.fword,
},
}).done((data)=>{ })
},
findAllFlower:function () { // 查询全部鲜花信息
$.ajax({
url:'http://localhost:3000/flower/getAllFlower',
type:"GET",
dataType:"json"
}).done((data)=>{
this.flowerArray=data;
})
}
},
}) </script>
</body>
</html>

vue2整合axios

为了更加方便的实现功能和理解,在这里我分步骤为大家讲解。争取有一个好的效果。vue整合axios其实和vue整合ajax差不多,如果想学习axios的相关文章,可以参考我的这一篇博客https://www.cnblogs.com/jjgw/p/12079892.html,这里面涉及关于axios的使用大部分讲解的都非常详细。欢迎大家评论和提出问题。

一、查询全部鲜花信息

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>axios和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/vue.js"></script>
<script src="javascripts/axios.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息 },
deleteFlower:function (id) { //删除鲜花信息 },
addFlower:function () { // 添加鲜花信息 },
updateFlower:function (id) { // 修改鲜花信息 },
findAllFlower:function () { // 查询全部鲜花信息
axios({
url:'http://localhost:3000/flower/getAllFlower',
method:"GET",
dataType:"json"
}).then((data)=>{
this.flowerArray=data.data;
})
}
},
}) </script>
</body>
</html>

二、根据条件查询鲜花信息

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>axios和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/vue.js"></script>
<script src="javascripts/axios.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息
this.fid=id;
axios({
url:'http://localhost:3000/flower/findFlowerById',
type:'GET',
params:{id:id}
}).then((data)=>{
this.fname=data.data[0].fname;
this.fprice=data.data[0].fprice;
this.fsituation=data.data[0].fsituation;
this.fuse=data.data[0].fuse;
this.fhc=data.data[0].fhc;
this.fword=data.data[0].fword;
})
},
deleteFlower:function (id) { //删除鲜花信息 },
addFlower:function () { // 添加鲜花信息 },
updateFlower:function (id) { // 修改鲜花信息 },
findAllFlower:function () { // 查询全部鲜花信息
axios({
url:'http://localhost:3000/flower/getAllFlower',
method:"GET",
dataType:"json"
}).then((data)=>{
this.flowerArray=data.data;
})
}
},
}) </script>
</body>
</html>

三、添加鲜花信息

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>axios和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/vue.js"></script>
<script src="javascripts/axios.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息 },
deleteFlower:function (id) { //删除鲜花信息 },
addFlower:function () { // 添加鲜花信息
axios({
url:'http://localhost:3000/flower/addFlower',
method:'POST',
data:{
fname:this.fname,
fprice:this.fprice,
fsituation:this.fsituation,
fuse:this.fuse,
fhc:this.fhc,
fword:this.fword,
}
}).then((data)=>{
this.result=data.data;
})
},
updateFlower:function (id) { // 修改鲜花信息 },
findAllFlower:function () { // 查询全部鲜花信息
axios({
url:'http://localhost:3000/flower/getAllFlower',
method:"GET",
dataType:"json"
}).then((data)=>{
this.flowerArray=data.data;
})
}
},
}) </script>
</body>
</html>

四、修改鲜花信息

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>axios和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/vue.js"></script>
<script src="javascripts/axios.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息
this.fid=id;
axios({
url:'http://localhost:3000/flower/findFlowerById',
type:'GET',
params:{id:id}
}).then((data)=>{
this.fname=data.data[0].fname;
this.fprice=data.data[0].fprice;
this.fsituation=data.data[0].fsituation;
this.fuse=data.data[0].fuse;
this.fhc=data.data[0].fhc;
this.fword=data.data[0].fword;
})
},
deleteFlower:function (id) { //删除鲜花信息 },
addFlower:function () { // 添加鲜花信息 },
updateFlower:function (id) { // 修改鲜花信息
axios({
url:'http://localhost:3000/flower/updateFlower',
method:'PUT',
data:{
fid:this.fid,
fname:this.fname,
fprice:this.fprice,
fsituation:this.fsituation,
fuse:this.fuse,
fhc:this.fhc,
fword:this.fword,
},
}).then((data)=>{
this.result=data.data;
})
},
findAllFlower:function () { // 查询全部鲜花信息
axios({
url:'http://localhost:3000/flower/getAllFlower',
method:"GET",
dataType:"json"
}).then((data)=>{
this.flowerArray=data.data;
})
}
},
}) </script>
</body>
</html>

五、删除鲜花信息

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>axios和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/vue.js"></script>
<script src="javascripts/axios.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息 },
deleteFlower:function (id) { //删除鲜花信息
axios({
url:'http://localhost:3000/flower/deleteFlower',
method:"DELETE",
data:{
id:id
},
}).then((data)=>{
this.result=data.data;
})
},
addFlower:function () { // 添加鲜花信息 },
updateFlower:function (id) { // 修改鲜花信息 },
findAllFlower:function () { // 查询全部鲜花信息
axios({
url:'http://localhost:3000/flower/getAllFlower',
method:"GET",
dataType:"json"
}).then((data)=>{
this.flowerArray=data.data;
})
}
},
}) </script>
</body>
</html>

六、全部代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>axios和vue操作mysql</title>
</head>
<body>
<div id="app">
<table border="1" width="800px" style="margin: 0 auto" cellspacing="0" cellpadding="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>价格</td>
<td>使用节日</td>
<td>鲜花用途</td>
<td>鲜花花材</td>
<td>花语</td>
<td>操作</td>
</tr>
<template v-for="(item,index) of flowerArray">
<tr>
<td>{{index+1}}</td>
<td>{{item.fname}}</td>
<td>{{item.fprice}}</td>
<td>{{item.fsituation}}</td>
<td>{{item.fuse}}</td>
<td>{{item.fhc}}</td>
<td>{{item.fword}}</td>
<td>
<input type="button" :data-id="item.fid" value="删除" @click="deleteFlower(item.fid)">
<input type="button" :data-id="item.fid" value="修改" @click="findFlowerById(item.fid)">
</td>
</tr>
</template>
</table>
<form>
名称:
<input type="text" v-model="fname"><br>
价格:
<input type="text" v-model="fprice"><br>
节日:
<input type="text" v-model="fsituation"><br>
用途:
<input type="text" v-model="fuse"><br>
花材:
<input type="text" v-model="fhc"><br>
花语:
<input type="text" v-model="fword"><br>
<span style="color: red">{{result}}</span><br>
<input type="button" @click="addFlower" value="添加鲜花">
<input type="button" @click="updateFlower" value="修改鲜花">
</form>
</div>
<script src="javascripts/vue.js"></script>
<script src="javascripts/axios.js"></script>
<script>
var vm=new Vue({
el:'#app',
data:{
fid:'',
fname:'',
fprice:'',
fsituation:'',
fuse:'',
fhc:'',
fword:'',
result:'',
flowerArray:[],
},
mounted(){
this.findAllFlower();
},
methods:{
findFlowerById:function (id) { //根据编号查询鲜花信息
this.fid=id;
axios({
url:'http://localhost:3000/flower/findFlowerById',
type:'GET',
params:{id:id}
}).then((data)=>{
console.log(data.data[0].fname);
this.fname=data.data[0].fname;
this.fprice=data.data[0].fprice;
this.fsituation=data.data[0].fsituation;
this.fuse=data.data[0].fuse;
this.fhc=data.data[0].fhc;
this.fword=data.data[0].fword;
})
},
deleteFlower:function (id) { //删除鲜花信息
axios({
url:'http://localhost:3000/flower/deleteFlower',
method:"DELETE",
data:{
id:id
},
}).then((data)=>{
this.result=data.data;
})
},
addFlower:function () { // 添加鲜花信息
axios({
url:'http://localhost:3000/flower/addFlower',
method:'POST',
data:{
fname:this.fname,
fprice:this.fprice,
fsituation:this.fsituation,
fuse:this.fuse,
fhc:this.fhc,
fword:this.fword,
}
}).then((data)=>{
this.result=data.data;
})
},
updateFlower:function (id) { // 修改鲜花信息
axios({
url:'http://localhost:3000/flower/updateFlower',
method:'PUT',
data:{
fid:this.fid,
fname:this.fname,
fprice:this.fprice,
fsituation:this.fsituation,
fuse:this.fuse,
fhc:this.fhc,
fword:this.fword,
},
}).then((data)=>{
this.result=data.data;
})
},
findAllFlower:function () { // 查询全部鲜花信息
axios({
url:'http://localhost:3000/flower/getAllFlower',
method:"GET",
dataType:"json"
}).then((data)=>{
this.flowerArray=data.data;
})
}
},
}) </script>
</body>
</html>

Node.js实操练习(一)之Node.js+MySQL+RESTful的更多相关文章

  1. 【强烈推荐,超详细,实操零失误】node.js安装 + npm安装教程 + Vue开发环境搭建

    node.js安装 + npm安装教程 + Vue开发环境搭建 [强烈推荐,超详细,实操零失误] 原博客园地址:https://www.cnblogs.com/goldlong/p/8027997.h ...

  2. k8s搭建实操记录干货二(node)

    #注:172.16.110.111为master,172.16.110.112\114为node1\node2(kubeadm join部分要等master完成后手工操作,其它可执行本脚本一键安装) ...

  3. 前端实操案例丨如何实现JS向Vue传值

    摘要:项目开发过程中,组件通过render()函数渲染生成,并在组件内部定义了自定义拖拽指令.自定义拖拽指令规定了根据用户可以进行元素拖拽.缩放等一系列逻辑处理的动作. 本文分享自华为云社区<[ ...

  4. [Node.js] 00 - Where do we put Node.js

    Ref: 前后端分离的思考与实践(五篇软文) 其实就是在吹淘宝自己的Midway-ModelProxy架构. 第一篇 起因 为了提升开发效率,前后端分离的需求越来越被重视, 同一份数据接口,我们可以定 ...

  5. Node.app – 用于 iOS App 开发的 Node.js 解释器

    Node.app 是用于 iOS 开发的 Node.js 解释器,它允许最大的代码重用和快速创新,占用资源很少,为您的移动应用程序提供 Node.js 兼容的 JavaScript API.你的客户甚 ...

  6. JS一般般的网页重构可以使用Node.js做些什么(转)

    一.非计算机背景前端如何快速了解Node.js? 做前端的应该都听过Node.js,偏开发背景的童鞋应该都玩过. 对于一些没有计算机背景的,工作内容以静态页面呈现为主的前端,可能并未把玩过Node.j ...

  7. nw.js桌面程序自动更新(node.js表白记)

    Hello Google Node.js 一个基于Google V8 的JavaScript引擎. 一个伟大的端至端语言,或许我对你的热爱源自于web这门极富情感的技术吧! 注: 光阴似水,人生若梦, ...

  8. node源码详解(三)—— js代码在node中的位置,process、require、module、exports的由来

    本作品采用知识共享署名 4.0 国际许可协议进行许可.转载保留声明头部与原文链接https://luzeshu.com/blog/nodesource3 本博客同步在https://cnodejs.o ...

  9. node.js 之 Hello,World in Node !

    创建一个js文件,把下面的内容粘贴进去,命名为helloworld.js. //加载 http 模块 var http = require("http"); //创建 http 服 ...

随机推荐

  1. H3C创建本地用户

    [H3C]Local-user wang                 //创建本地用户--对应上面scheme的 [H3C-luser-wang]Password cipher 456      ...

  2. 2018-9-30-C#-传入-params-object-长度

    title author date CreateTime categories C# 传入 params object 长度 lindexi 2018-09-30 18:33:20 +0800 201 ...

  3. C# 转换类型和字符串

    有时候我们需要互转类型和字符串,把字符串转类型.把类型转字符串. 如果是基础类型,可以使用 x.Parse 这个方法,很多基础类型都支持. 那么我们可以使用 TypeDescriptor string ...

  4. CodeChef Ada Pawns

    最小割 留下最多的点 形如左上或者右上没有点的点一定会留下 对于斜着的关系的两个点不能共存 黑白行染色! 白行的点称为 白点,黑点类似 反着连关系 对于一定会留下的,S到白点,黑点到T,都连inf 不 ...

  5. 【47.63%】【hdu 1532】Drainage Ditches

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...

  6. 两种高效的事件处理模式(Proactor和Reactor)

    典型的多线程服务器的线程模型 1. 每个请求创建一个线程,使用阻塞式 I/O 操作 这是最简单的线程模型,1个线程处理1个连接的全部生命周期.该模型的优点在于:这个模型足够简单,它可以实现复杂的业务场 ...

  7. Python之end关键字使用

    关键字end可以用于将结果输出到同一行,或者在输出的末尾添加不同的字符,实例如下: a, b = 0, 1 while b < 1000: print(b, end=',') a, b = b, ...

  8. 不仅仅是双11大屏—Flink应用场景介绍

    双11大屏 每年天猫双十一购物节,都会有一块巨大的实时作战大屏,展现当前的销售情况. 这种炫酷的页面背后,其实有着非常强大的技术支撑,而这种场景其实就是实时报表分析. 实时报表分析是近年来很多公司采用 ...

  9. $SP15637\ GNYR04H\ -\ Mr\ Youngs\ Picture\ Permutations$

    传送门 Description 杨先生希望为他的班级拍照.学生将排成一行,每行不超过后面的行,并且行的左端对齐.例如,可以安排12名学生排列(从后到前)5,3,3和1名学生. X X X X X X ...

  10. FacadePattern(外观模式)-----Java/.Net

    外观模式(Facade Pattern)隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口.这种类型的设计模式属于结构型模式,它向现有的系统添加一个接口,来隐藏系统的复杂性