Node.js实操练习(一)之Node.js+MySQL+RESTful(2)

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用版 2核4GB 50GB
简介: Node.js实操练习(一)之Node.js+MySQL+RESTful

 Node.js实操练习(一)之Node.js+MySQL+RESTful(1)https://developer.aliyun.com/article/1543051

四、修改鲜花信息
DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax和vue操作mysqltitle>
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操作mysqltitle>
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操作mysqltitle>
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>

 Node.js实操练习(一)之Node.js+MySQL+RESTful(3)https://developer.aliyun.com/article/1543054

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
9天前
|
JavaScript
Node.js实操练习(一)之Node.js+MySQL+RESTful(4)
Node.js实操练习(一)之Node.js+MySQL+RESTful
|
9天前
|
JavaScript 前端开发
Node.js实操练习(一)之Node.js+MySQL+RESTful(3)
Node.js实操练习(一)之Node.js+MySQL+RESTful
|
10天前
|
JavaScript 前端开发 关系型数据库
Node.js实操练习(一)之Node.js+MySQL+RESTful(1)
Node.js实操练习(一)之Node.js+MySQL+RESTful
|
1月前
|
JavaScript 前端开发
node.js 快速入门
node.js 快速入门
40 0
|
10月前
|
Web App开发 JavaScript 前端开发
Node.js -- Node.js概述与安装和运行
Node.js -- Node.js概述与安装和运行
|
JavaScript 网络协议 Windows
Node.js入门之path模块
前面我们介绍了什么是Node.js,今天我们主要再来说说path模块。path模块主要是对系统中路径的一些操作。比如常用的获取文件路径、文件名、文件扩展名等。
210 0
|
JavaScript 前端开发 关系型数据库
node.js操作MySQL数据库
node.js操作MySQL数据库
119 0
|
SQL JavaScript 关系型数据库
如何使用Node.js连接数据库
在前面的文章中我们有手把手使用docker创建数据库,这里就直接沿用之前创建的数据库 首先启动docker,把之前的mysql容器运行起来
321 0
如何使用Node.js连接数据库
|
SQL JavaScript 前端开发
Node.js操作MySQL数据库
《前端基础》
187 0
|
JavaScript Linux iOS开发
node.js 安装和配置|学习笔记
快速学习 node.js 安装和配置
182 0
node.js 安装和配置|学习笔记