写在前面 
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家:人工智能学习网站 
 
Vue 
 
前言 概述 :Vue是一款前端渐进式框架,可以提高前端开发效率。
特点 :
 Vue通过MVVM模式,能够实现视图与模型的双向绑定。
 简单来说,就是数据变化的时候, 页面会自动刷新, 页面变化的时候,数据也会自动变化.
Vue.js三种安装方式 此处引荐下大佬的文章 讲的非常详细Vue.js三种方式安装 
一、 Vue导入 概述 :Vue是一个类似于Jquery的一个JS框架,所以,如果想使用Vue,则在当前页面导入Vue.js文件即可。
语法 :
1 2 3 4 5 6 7 8 9 <!-- 在线导入 --> <!-- 开发环境版本,包含了用帮助的命令行警告 --> <script  src ="https://cdn.jsdelivr.net/npm/vue/dist/vue.js" > </script > <!-- 生产环境版本,优化了尺寸和速度 --> <script  src ="https://cdn.jsdelivr.net/npm/vue" > </script > <!-- 本地导入 --> <script  src ="node_modules/vue/dist/vue.js" > </script > 12345678 
 
案例 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <div id="app" >     <h1 > 用户名:<input  type ="text"  v-model ="name" /> </h1 >   <br />      <h1 > 您输入的用户名是: {{name}}</h1 >  </div> <script  type ="text/javascript" >          var  app = new  Vue ({                  el : "#app" ,                  data : {             name : ""          }     }); </script > 12345678910111213141516 
 
二、Vue基本语法 1.钩子函数 **概述:**钩子函数, 其实就是Vue提前定义好的事件, 其作用类似于Servlet的init方法和distory方法
语法 :
1 2 3 4 5 6 7 8 9 10 <script type="text/javascript" >     var  app = new  Vue ({         el :"#app" ,                  created ( ) {             console .log ("created..." );         }     }); </script> 123456789 
 
补充:Vue声明周期和钩子函数  (1)什么是vue生命周期?
Vue 实例从创建到销毁的过程,就是生命周期。也就是从开始创建、初始化数据、编译模板、挂载Dom→渲染、更新→渲染、卸载等一系列过程,我们称这是 Vue 的生命周期。
(2)vue生命周期的作用是什么?
Vue生命周期中有多个事件钩子,让我们在控制整个Vue实例过程时更容易形成好的逻辑。
(3)vue生命周期总共有几个阶段?
可以总共分为8个阶段:创建前/后, 载入前/后,更新前/后,销毁前/后。
(4)第一次页面加载会触发哪几个钩子?
第一次页面加载时会触发 beforeCreate, created, beforeMount, mounted 这几个钩子
(5)DOM 渲染在 哪个周期中就已经完成?
DOM 渲染在 mounted 中就已经完成了。
(6)简单描述每个周期具体适合哪些场景?
生命周期钩子的一些使用方法:
beforecreate : 可以在此阶段加loading事件,在加载实例时触发;
created : 初始化完成时的事件写在这里,如在这结束loading事件,异步请求也适宜在这里调用;
mounted : 挂载元素,获取到DOM节点;
updated : 如果对数据统一处理,在这里写上相应函数;
beforeDestroy : 可以做一个确认停止事件的确认框;
nextTick : 更新数据后立即操作dom;
2. 插值表达式 **概述:**插值表达式用户把vue中所定义的数据,显示在页面上. 插值表达式允许用户输入”JS代码片段”
语法 :{{ 变量名/对象.属性名 }}
案例 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 <html  lang ="en" > <head >     <meta  charset ="UTF-8" >      <title > vue插值表达式</title >      <script  src ="node_modules/vue/dist/vue.js" > </script >  </head > <body >     <div  id ="app" >          <h1 > 欢迎来到--{{ name }}</h1 >      </div >      <script  type ="text/javascript" >                   var  app = new  Vue ({                          el :"#app" ,                          data :{                 name :"白大锅"              }         });      </script > </body > </html > 1234567891011121314151617181920212223 
 
3.显示数据(v-text和v-html) 概述: 
 v-text和v-html专门用来展示数据, 其作用和插值表达式类似。v-text和v-html可以避免插值闪烁问题.
 当网速比较慢时, 使用双大括号来展示数据, 有可能会产生插值闪烁问题。
 插值闪烁: 在数据未加载完成时,页面会显示出原始的双大括号, 过一会才会展示正常数据.
语法 :
1 2 3 v-text:<span  v-text ="msg" > </span > 	 v-html:<span  v-html ="msg" > </span > 	 12 
 
区别 :
1 2 3 v-text:把数据当作纯文本显示. v-html:遇到html标签,会正常解析 12 
 
4.数据双向绑定数据(v-model) 概述: 
 Vue的双向绑定可以实现: 数据变化的时候, 页面会自动刷新, 页面变化的时候,数据也会自动变化.
注意: 
双向绑定, 只能绑定**“文本框,单选按钮,复选框,文本域,下拉列表”**等 
文本框/单选按钮/textarea, 绑定的数据是字符串类型 
单个复选框, 绑定的是boolean类型 
多个复选框, 绑定的是数组 
select单选对应字符串,多选对应也是数组 
 
4.1.绑定文本框 代码: 
1 2 3 4 5 6 7 8 9 10 11 12 13 <div id="app" >     用户名: <input  type ="text"  v-model ="username" />  </div> <script  type ="text/javascript" >     var  app = new  Vue ({         el :"#app" ,         data :{                          username :""          }     }); </script > 123456789101112 
 
效果: 
4.2.绑定单个复选框 代码: 
1 2 3 4 5 6 7 8 9 10 11 12 <div id="app" >     <input  type ="checkbox"  v-model ="agree" > 同意<br >  </div > <script  type ="text/javascript" >     var  app = new  Vue ({         el :"#app" ,         data :{             agree :true          }     }); </script > 1234567891011 
 
效果: 
4.3.绑定多个复选框 代码: 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <div id="app" >     <input type="checkbox" value="Java" v-model="language">Java<br>     <input type="checkbox" value="Python" v-model="language">Python<br>     <input type="checkbox" value="Swift" v-model="language">Swift<br> </div> <script type="text/javascript">     var app = new Vue({         el:"#app",         data:{             //数组中的值,就是被选中的元素的value属性值             language:["Java","Python"]         }     }); </script> 1234567891011121314 
 
效果: 
例子:传json格式跟formData格式的两种情况
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 <template>   <div class="from_box">     <form action="">       <input type="text"  placeholder="请输入昵称" v-model="formMess.account">       <input type="password" placeholder="请输入密码" v-model="formMess.act_pwd">       <input type="text" placeholder="请输入手机号" v-model="formMess.phone">     </form>     <span class="but" @click="onSubmit()">提交</span>   </div> </template>   <script> import axios from 'axios';   export default {   name: "from",   data() {     return {     	formMess:{ 	    "account":"", 	    "act_pwd":"", 	    "phone":"" 	}     };   },   methods: {     onSubmit() {       /* json格式提交: */       // let formData = JSON.stringify(this.formMess);         /* formData格式提交: */       let formData = new FormData();       for(var key in this.formMess){         formData.append(key,this.formMess[key]);       }           axios({ 	    method:"post", 	    url:"xxxxxxx", 	    headers: { 		  "Content-Type": "multipart/form-data" 	    }, 	    withCredentials:true, 	    data:formData 	}).then((res)=>{             console.log(res);         });     }   } }; </script>   <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped lang="less"> .from_box{   form{     width:90%;     margin: auto;     border:.01rem solid gray;     display: flex;     flex-wrap: wrap;     input{       width:80%;       height:.5rem;       margin-bottom: .2rem;       border:.01rem solid black;       height:.5rem;     }   }   .but{     font-size: .14rem;     margin-left:5%;   } } </style> 
 
5.事件处理(v-on) 5.1.事件绑定(v-on) 概述: 
 Vue中也可以给页面元素绑定事件.
语法 :
1 2 3 4 5 <button  v-on:事件名 ="函数名/vue表达式" > 点我</button > <button  @事件名 ="函数名/vue表达式" > 点我</button > 1234 
 
注意: 
 Vue支持html中所有已知事件. 如: @click, @submit等, 只不过事件的名字不带on
案例 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <html lang="en" > <head >     <meta  charset ="UTF-8" >      <title > vue事件处理</title >      <script  src ="node_modules/vue/dist/vue.js" > </script >  </head > <body >     <div  id ="app" >          <button  @click ="show" > 点我</button >      </div >      <script  type ="text/javascript" >                   var  app = new  Vue ({                          el :"#app" ,                          methods :{                                  show ( ) {                     alert ("Hello Vue!!!" );                 }             }         });      </script > </body > </html > 
 
5.2.事件修饰符 **概述:**事件修饰符主要对事件的发生范围进行限定
语法 :
1 2 <button @事件名.事件修饰符="函数名/vue表达式" >点我</button> 1 
 
分类: 
1 2 3 4 5 6 .stop  :阻止事件冒泡, 也就是当前元素发生事件,但当前元素的父元素不发生该事件 .prevent  :阻止默认事件发生 .capture  :使用事件捕获模式, 主动获取子元素发生事件, 把获取到的事件当自己的事件执行 .self  :只有元素自身触发事件才执行。(冒泡或捕获的都不执行) .once  :只执行一次 12345 
 
案例 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <html lang="en" > <head >     <meta  charset ="UTF-8" >      <title > vue事件处理</title >      <script  src ="node_modules/vue/dist/vue.js" > </script >  </head > <body >     <div  id ="app" >          <button  @click ="show" > 点我</button >      </div >      <script  type ="text/javascript" >                   var  app = new  Vue ({                          el :"#app" ,                          methods :{                                  show ( ) {                     alert ("Hello Vue!!!" );                 }             }         });      </script > </body > </html > 
 
6.循环遍历(v-for) 6.1.遍历数组 语法 :
1 2 3 v-for ="item in items"  v-for ="(item,index) in items"  12 
 
items:要迭代的数组 item:存储数组元素的变量名 index:迭代到的当前元素索引,从0开始。代码 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <div id="app" > 	<ul >          <li  v-for ="(user, index) in users" >          	{{index}}--{{user.name}}--{{user.age}}--{{user.gender}}         </li >  	</ul >  </div> <script >     var  app = new  Vue ({         el :"#app" ,         data : {             users :[                 {"name" :"白卓冉" ,"age" :8 ,"gender" :"男" },                 {"name" :"白大锅" ,"age" :12 ,"gender" :"女" },                 {"name" :"白仙女" ,"age" :4 ,"gender" :"男" }             ]         }     }); </script > 
 
6.2.遍历对象 语法 :
1 2 3 4 v-for ="value in object"  v-for ="(value,key) in object"  v-for ="(value,key,index) in object"  123 
 
value,对象的值 key, 对象的键 index, 索引,从0开始代码 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 <div id="app" > 	<ul >          <li  v-for ="(value,key,index) in person" >          	{{index}}--{{key}}--{{value}}         </li >  	</ul >  </div> <script >     var  app = new  Vue ({         el :"#app" ,         data : {             person :{"name" :"白大锅" , "age" :3 , "address" :"中国" }         }     }); </script > 
 
6.3.key 概述: 
 :key 一般配合v-for一起使用. 用来在特定情况下, 保证被遍历的数组中的元素的顺序.
案例: 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 <div  id ="app" >     <button  @click ="add" > 添加</button >      <ul >          <li  v-for ="name in list" >              <input  type ="checkbox" >  {{name}}         </li >      </ul >  </div > <script >     var  app = new  Vue ({         el : '#app' ,         data : {             list : ["孙悟空" , "猪八戒" , "沙和尚" ]         },         methods : {             add ( ) {                                  this .list .unshift ("唐僧" );             }         }     }); </script > 
 
效果: 解决方案: 
1 2 3 4 5 6 7 8 9 10 <div  id ="app" >     <button  @click ="add" > 添加</button >      <ul >                   <li  v-for ="name in list"  :key ="name" >              <input  type ="checkbox" >  {{name}}         </li >      </ul >  </div > 123456789 
 
7.判断语法(v-if和v-show) 概述: 
v-if与v-show可以根据条件的结果,来决定是否显示指定内容.
 v-if: 条件不满足时, 元素不会存在.
 v-show: 条件不满足时, 元素不会显示(但仍然存在).
 
案例 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 <div  id ="app" > 	<button  @click ="show = !show" > 点我</button >  	<h1  v-if ="show" > Hello v-if.</h1 >      <h1  v-show ="show" > Hello v-show.</h1 >  </div > <script >     var  app = new  Vue ({         el :"#app" ,         data : {         	show :true          }     }); </script > 12345678910111213 
 
8.显示数据(v-bind) 概述: 
v-bind的作用和插值表达式差不多, 只不过, v-bind主要用于动态设置标签的属性值
 
语法 :
 
案例 :
1 2 3 4 5 6 7 8 9 10 11 12 13 <div  id ="app" >     <input  type ="button"  :value ="msg" />  </div > <script  type ="text/javascript" >     var  app = new  Vue ({         el :"#app" ,         data :{            msg :"我是按钮"          }     }); </script > 123456789101112 
 
9.Vue页面跳转(两种方法) 9.1.方法一(标签实现) 1 2 3 4 5 6 7 <router-link  :to ="{name: 'bookshelf', params: { entityId: this.entityId } }"               :class ="{'flex-item-1':'flex-item-1',cur:tabs[0].isShow}"  href ="javascript:" >               <span  class ="tabNav-ico tabNav-book" > </span >                <span  class ="tabNav-txt" > 书 架</span >  </router-link > 123456 
 
9.1.方法二(this.$router.push()实现) 当this.$router.push()只有一个参数时 默认为跳转地址 最多可传两个参数 第二个参数为地址参数
1 2 3 4 5 6 7 8 9 10 11 <a @click="toIndex"  :class ="{'flex-item-1':'flex-item-1',cur:tabs[2].isShow}"  href="javascript:" >       <span  class ="tabNav-ico tabNav-home" > </span >        <span  class ="tabNav-txt" > 首 页</span >  </a> toIndex : function ( ){        this .$router .push ("/?entityId=" + localStorage .getItem ("entityId" )); } 12345678910 
 
三、Vue其他语法 3.1.计算属性 概述 :计算属性就是一个提前定义好的方法, 该方法可以看作是一个特殊的值, 可以在插值表达式中使用.
语法 :
1 2 3 4 5 6 7 8 9 10 11  var  app = new  Vue ({      el :"#app" ,            computed :{                    属性名(){              return  "返回值" ;          }      } }); 12345678910 
 
案例: 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <div id="app" >     <h1 > {{birth}}</h1 >      <h1  v-text ="birth" > </h1 >      <h1  v-html ="birth" > </h1 >  </div> <script  type ="text/javascript" >     var  app = new  Vue ({         el :"#app" ,         computed :{                          birth ( ){                 let  date = new  Date ();                 let  year = date.getFullYear ();                 let  month = date.getMonth ()+1 ;                 let  day = date.getDay ();                 return  year + "-"  + month + "-"  + day;             }         }     }); </script > 
 
3.2.watch监控 概述 :
 watch可以监听简单属性值及其对象中属性值的变化.
 watch类似于onchange事件,可以在属性值修改的时候,执行某些操作.
语法 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 var  app = new  Vue ({    el :"#app" ,     data :{         message :"白大锅" ,         person :{"name" :"heima" , "age" :13 }     },          watch :{                  message (newValue, oldValue ){         	console .log ("新值:"  + newValue + ";旧值:"  + oldValue);         },                  person : {                          deep : true ,                          handler (obj ){                 console .log ("name = "  + obj.name  + "; age="  + obj.age );             }         }     } }); 
 
四、Vue组件 4.1.基本使用 概述: 
组件, 类似于模版, 模块. 在项目需要重用某个模块(头部、尾部、新闻。。。)的时候,可以将模块抽取成组件,其它页面中注册组件并引用。
 
案例: 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 <div  id ="app" >           </div > <script  type ="text/javascript" >          const  counterTemp = {                  template :`<button @click='num++'>你点击了{{num}}次</button>` ,                  data ( ){            return  {               num :0             }         }      };                             var  app = new  Vue ({         el :"#app" ,                  components :{                          counter : counterTemp         }     }); </script > 
 
注意: 
组件的模版中, 只能书写一个跟标签 
组件的定义必须放在Vue创建对象之前, 否则报错 
 
 
4.2.父组件向子组件通信 概述: 
子组件无法直接使用父组件中的数据, 如果需要使用, 则必须由父组件把数据传递给子组件才可以.
本质: 让子组件中的属性与父组件中的属性进行关联绑定, 然后子组件使用该属性, 这样才能做到数据传递
 
意义: 
可以把父组件中的数据, 更新传递到子组件
 
示例: 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 <div  id ="app" >            </div > <script >     var  aaa = {                  template : `<h2>{{num}}---{{number}}--{{ids}}--{{person}}</h2>` ,                  data ( ) {             return  {                 num : 0              }         },                  props : {                          number : "" ,                          ids : [],                          person : {}                      }     };          Vue .component ("aaa" , aaa);     var  app = new  Vue ({         el : "#app" ,         data : {             count : 5 ,             arr : [1 , 2 , 3 ],             p : {username : "zhangsan" , age : 23 }         }     }); </script > 
 
4.3.子组件向父组件通信 概述: 
子组件无法直接给父组件传递数据. 也无法操作父组件中的数据, 更无法调用父组件中的方法.
所以, 所谓的子组件向父组件通讯, 其实就是想办法让子组件调用父组件的方法. 进而响应到父组件中的数据.
 
意义: 
子组件可以调用父组件中的方法
 
示例: 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 <div  id ="app" >     <h1 > 父组件中:app_num={{app_num}}</h1 >                      </div > <script >          let  counter = {         template : `               <div>                    <h1>子组件中:counter_num={{counter_num}}</h1>                    <input type="button" @click="fun1" value="+"/>                    <input type="button" @click="fun2" value="-"/>             </div>                 ` ,        props :{                          counter_num :null ,                          aaa :function ( ){},                          bbb :function ( ){},         },                methods :{             fun1 ( ){                                  return  this .$emit("aaa" );             },             fun2 ( ){                                  return  this .$emit("bbb" );             }         }     }     var  app = new  Vue ({         el : '#app' ,         data : {             app_num : 0          },         components : {             counter         },         methods :{             add ( ){                 this .app_num ++;             },             rem ( ){                 this .app_num --;             }         }     }); </script > 
 
五、axios异步请求 5.1 axios概述 概述: 
axios是一个基于 promise 的 HTTP 库, 主要用于:发送异步请求获取数据 。
常见的方法:
 axios(config)
 axios.get(url, [config])
 axios.post(url, [data])
 
发送数据config常用参数: 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 {     url : '请求的服务器' , 	method : '请求方式' ,           params : {     	参数名: 参数值     }, 	     data : {     	参数名: 参数值     }, 	 	responseType : 'json'  } 
 
响应数据常用参数: 
1 2 3 4 5 6 7 8 {     data : {},		     status : 200 ,	     statusText : 'OK' ,	      headers : {},	     config : {}		 } 
 
5.2.Get请求 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 var  app = new  Vue ({    el : "#app" ,     data : {         user : {}     },          created ( ) {                  axios.get ("请求路径" ,{                          params : {                 name :"zhangsan" ,                 age :23              },                          responseType : 'json'          }).then (res  =>  {                          console .log (res);                          app.user  = res.data ;         }).catch (err  =>  {                          console .log (err);         });     } }); 
 
5.3.Post请求 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 var  app = new  Vue ({    el : "#app" ,     data : {         user : {}     },          created ( ) {                   axios.post ("请求路径" ,{                 name :"zhangsan" ,                 age :23              }).then (res  =>  {                 console .log (res);                 app.user  = res.data ;             }).catch (err  =>  {                 console .log (err);             });     } }); 
 
5.4.跨域请求 
跨域请求:在前端js中如果发送异步请求的话,请求的地址与当前服务器的ip或者端口号不同都是跨域请求.
跨域请求需要在服务提供方, 开启允许跨域请求
 
六、VueJs Ajax 6.1.vue-resource vue-resource是Vue.js的插件提供了使用XMLHttpRequest或JSONP进行Web请求和处理响应的服务。 当vue更新 到2.0之后,作者就宣告不再对vue-resource更新,而是推荐的axios,在这里大家了解一下vue-resource就可以。 vue-resource的github: https://github.com/pagekit/vue-resource 
6.2.axios Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中 axios的github:https://github.com/axios/axios 
6.2.1.引入axios 
首先就是引入axios,如果你使用es6,只需要安装axios模块之后 import axios from ‘axios’; //安装方法 npm install axios //或 bower install axios
 
当然也可以用script引入
1 2 <script src="https://unpkg.com/axios/dist/axios.min.js" ></script> 1 
 
6.2.2.get请求 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 axios.get ('/user?ID=12345' ) .then (function (response ){ console .log (response);}).catch (function (err ){ console .log (err);}); axios.get ('/user' ,{ params :{ID :12345 } }).then (function (response ){ console .log (response);}).catch (function (err ){ console .log (err);}); 1234567891011121314151617 
 
6.2.3.post请求 1 2 3 4 5 6 7 8 9 10 11 axios.post ('/user' ,{ firstName :'Fred' ,lastName :'Flintstone' }) .then (function (res ){ console .log (res);}) .catch (function (err ){ console .log (err);}); 
 
为方便起见,为所有支持的请求方法提供了别名
1 2 3 4 5 6 7 8 axios.request(config) axios.get(url[, config]) axios.delete(url[, config]) axios.head(url[, config]) axios.post(url[, data[, config]]) axios.put(url[, data[, config]]) axios.patch(url[, data[, config]]) 1234567 
 
七、综合案例 7.1.需求 完成用户的查询与修改操作
7.2. 数据库设计与表结构 1 2 3 4 5 6 7 8 9 10 11 CREATE  DATABASE vuejsdemo;USE vuejsdemo; CREATE  TABLE  USER (id INT  PRIMARY  KEY AUTO_INCREMENT, age INT , username VARCHAR (20 ), PASSWORD VARCHAR (50 ), email VARCHAR (50 ), sex VARCHAR (20 ) ) 
 
User类
1 2 3 4 5 6 7 8 9 10 public  class  User  {private  Integer id;private  String username;private  String password;private  String sex;private  int  age;private  String email;省略getter/setter } 
 
7.3.服务器端 7.3.1.配置文件 web.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 <?xml version="1.0"  encoding="UTF-8" ?> <web-app  xmlns ="http://xmlns.jcp.org/xml/ns/javaee"  	xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"  	xsi:schemaLocation ="http://xmlns.jcp.org/xml/ns/javaee  	http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 	version ="3.1"  	metadata-complete ="true" > 	 	<context-param >  		<param-name > contextConfigLocation</param-name >  		<param-value > classpath:applicationContext.xml</param-value >  	</context-param >  	 	<listener >  		<listener-class >  			org.springframework.web.context.ContextLoaderListener 		</listener-class >  	</listener >  	 	<servlet >  		<servlet-name > springmvcDispatcherServlet</servlet-name >  		<servlet-class > org.springframework.web.servlet.DispatcherServlet</servlet-class >  		 		<init-param >  			<param-name > contextConfigLocation</param-name >  			<param-value > classpath:springmvc.xml</param-value >  		</init-param >  		 		<load-on-startup > 1</load-on-startup >  	</servlet >  	<servlet-mapping >  		<servlet-name > springmvcDispatcherServlet</servlet-name >  		<url-pattern > *.do</url-pattern >  	</servlet-mapping >  	 	<filter >  		<filter-name > CharacterEncodingFilter</filter-name >  		<filter-class > org.springframework.web.filter.CharacterEncodingFilter</filter-class >  		 		<init-param >  			<param-name > encoding</param-name >  			<param-value > UTF-8</param-value >  		</init-param >  		 		<init-param >  			<param-name > forceEncoding</param-name >  			<param-value > true</param-value >  		</init-param >  	</filter >  	 	<filter-mapping >  		<filter-name > CharacterEncodingFilter</filter-name >  		<url-pattern > /*</url-pattern >  	</filter-mapping >  	<welcome-file-list >  		<welcome-file > index.html</welcome-file >  		<welcome-file > index.htm</welcome-file >  		<welcome-file > index.jsp</welcome-file >  		<welcome-file > default.html</welcome-file >  		<welcome-file > default.htm</welcome-file >  		<welcome-file > default.jsp</welcome-file >  	</welcome-file-list >  </web-app > 
 
springmvc.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <?xml version="1.0"  encoding="UTF-8" ?> <beans  xmlns ="http://www.springframework.org/schema/beans"  	xmlns:mvc ="http://www.springframework.org/schema/mvc"  	xmlns:context ="http://www.springframework.org/schema/context"  	xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"  	xsi:schemaLocation ="http://www.springframework.org/schema/beans  	http://www.springframework.org/schema/beans/spring-beans.xsd 	http://www.springframework.org/schema/mvc 	http://www.springframework.org/schema/mvc/spring-mvc.xsd 	http://www.springframework.org/schema/context 	http://www.springframework.org/schema/context/spring-context.xsd" >	 	<context:component-scan  base-package ="com.itheima" >  		 		<context:include-filter  type ="annotation"   		expression ="org.springframework.stereotype.Controller" /> 	</context:component-scan >  	<mvc:annotation-driven > </mvc:annotation-driven >  </beans > 
 
applicationContext.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 <?xml version="1.0"  encoding="UTF-8" ?> <beans  xmlns ="http://www.springframework.org/schema/beans"  	xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"  	xmlns:aop ="http://www.springframework.org/schema/aop"  	xmlns:tx ="http://www.springframework.org/schema/tx"  	xmlns:context ="http://www.springframework.org/schema/context"  	xsi:schemaLocation ="http://www.springframework.org/schema/beans  	http://www.springframework.org/schema/beans/spring-beans.xsd 	http://www.springframework.org/schema/tx 	http://www.springframework.org/schema/tx/spring-tx.xsd 	http://www.springframework.org/schema/aop 	http://www.springframework.org/schema/aop/spring-aop.xsd 	http://www.springframework.org/schema/context 	http://www.springframework.org/schema/context/spring-context.xsd" >	 	<context:component-scan  base-package ="com.itheima" >  	 		<context:exclude-filter  type ="annotation"   		expression ="org.springframework.stereotype.Controller" /> 	</context:component-scan >  	 	<context:property-placeholder  location ="classpath:db.properties" />  	 	<bean  id ="sqlSessionFactory"  class ="org.mybatis.spring.SqlSessionFactoryBean" >  		 		<property  name ="dataSource"  ref ="dataSource" />  		 		<property  name ="configLocation"  value ="classpath:SqlMapConfig.xml" />  	</bean >  	 	<bean  id ="dataSource"  class ="com.mchange.v2.c3p0.ComboPooledDataSource" >  		<property  name ="driverClass"  value ="${jdbc.driver}" > </property >  		<property  name ="jdbcUrl"  value ="${jdbc.url}" > </property >  		<property  name ="user"  value ="${jdbc.username}" > </property >  		<property  name ="password"  value ="${jdbc.password}" > </property >  	</bean >  	 	<bean  class ="org.mybatis.spring.mapper.MapperScannerConfigurer" >  		<property  name ="basePackage"  value ="com.itheima.dao" />  	</bean >  	<tx:annotation-driven />  	 	<bean  id ="transactionManager"   		class ="org.springframework.jdbc.datasource.DataSourceTransactionManager" > 		<property  name ="dataSource"  ref ="dataSource" />  	</bean >  </beans > 
 
db.properties
1 2 3 4 5 jdbc.driver =com.mysql.jdbc.Driver jdbc.url =jdbc:mysql://localhost:3306/vuejsDemo jdbc.username =root jdbc.password =root 1234 
 
7.3.2.Controller 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 @RequestMapping("/user") @Controller @ResponseBody public  class  UserController  {	@Autowired  	private  IUserService userService; 	@RequestMapping(value="/findAll.do")  	public  List<User> findAll ()  { 		return  userService.findAll(); 	} 	@RequestMapping(value="/findById.do")  	public  User findById (Integer id)  { 		return  userService.findById(id); 	} 	@RequestMapping(value="/update.do")  	public  User update (@RequestBody  User user)  { 		return  userService.update(user); 	} } 
 
7.3.3.Dao 1 2 3 4 5 6 7 8 9 10 public  interface  IUserDao  {	@Select("select * from user")  	public  List<User> findAll () ; 	@Select("select * from user where id=#{id}")  	User findById (Integer id) ; 	@Update("update user set username=#{username},password=#{password},sex=#{sex},age=#  	{age},email=#{email} where id=#{id}") 	void  update (User user) ; } 123456789 
 
7.4.客户端 7.4.1.user.html页面 原因种种 页面代码暂时提供不了 思路大概就是这些 嘻嘻~
7.4.2.user.js 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 var  vue = new  Vue ({	el : "#app" , 	data : { 		user : {id :"" ,username :"aaa" ,password :"" ,age :"" ,sex :"" ,email :"" }, 		userList : [] 	}, 	methods : { 		findAll : function  ( ) { 			var  _this = this ; 			axios.get ("/vuejsDemo/user/findAll.do" ).then (function  (response ) { 				_this.userList  = response.data ; 				console .log (_this.userList ); 			}).catch (function  (err ) { 				console .log (err); 			}); 		}, 		findById : function  (userid ) { 			var  _this = this ; 			axios.get ("/vuejsDemo/user/findById.do" , { 				params : { 					id : userid 				} 			}).then (function  (response ) { 				_this.user  = response.data ; 				$('#myModal' ).modal ("show" ); 			}).catch (function  (err ) { 			}); 		}, 		update : function  (user ) { 			var  _this = this ; 			axios.post ("/vuejsDemo/user/update.do" ,_this.user ).then (function  (response ) { 				_this.findAll (); 			}).catch (function  (err ) { 			}); 		} 	}, 	created ( ){ 		this .findAll (); 	} });