new Vue({ el:"#app" , data:{ user:{ id:"", username:"", password:"", age:"", sex:"", }, userList:[] }, methods:{ findAll:function () { //在当前方法中定义一个变量,表明是vue对象 var _this= this; axios.get(‘/day01_eesy_vuejsdemo/user/findAll.do‘) .then(function (response) { // handle success _this.userList=response.data; console.log(response); }) .catch(function (error) { // handle error console.log(error); }) .finally(function () { // always executed }); }, findById:function (userid) { //在当前方法中定义一个变量,表明是vue对象 var _this= this; axios.get(‘/day01_eesy_vuejsdemo/user/findById.do‘,{params:{id:userid}}) .then(function (response) { // handle success _this.user=response.data; $("#myModal").modal("show"); console.log(response); }) .catch(function (error) { // handle error console.log(error); }) .finally(function () { // always executed }); }, update:function (user) { //post请求 //在当前方法中定义一个变量,表明是vue对象 var _this= this; axios.post(‘/day01_eesy_vuejsdemo/user/updateUser.do‘, _this.user) .then(function (response) { _this.findAll(); console.log(response); }) .catch(function (error) { console.log(error); }); } }, created:function(){ this.findAll(); }});
原文地址:https://www.cnblogs.com/newcityboy/p/12222730.html
时间: 2024-10-06 20:16:48