html >
汽车管理系统
汽车管理系统
{{car.id}}
{{car.name}}
{{car.price}}
{{car.speed}}
{{car.color}}
添加汽车
var app=new Vue({
el:”#app”,
data:{
cars:[],
car:{id:0,name:””,price:””,speed:””,color:””},
name:””,
methods:{
order(){
this.carInfo();
orderBy(){
axios.get(“http://127.0.0.1:3000/api/cars/order/orderBy”)
.then(respons =>{
app.cars=respons.data.data;
console.log(this.cars);
.catch(err =>{
throw err;
search(){
if(this.name==””){
this.carInfo();
}else{
axios.get(“http://127.0.0.1:3000/api/cars/”+this.name)
.then(respons =>{
app.cars=[respons.data.data];
console.log(this.cars);
.catch(err =>{
throw err;
carInfo(){
axios.get(“http://127.0.0.1:3000/api/cars/”+this.name)
.then(respons =>{
this.cars=respons.data.data;
.catch(err =>{
throw err;
del(car,i){
if(confirm(“你确定要删除吗?”)){
let url=”http://127.0.0.1:3000/api/cars/”+car.id
axios.delete(url)
.then(data =>{
if(data.data.status===”ok”){
alert(“删除成功”)
this.cars.splice(i,1);
}else{
alert(“删除失败”)
.catch(err =>{
throw err;
return false;
edit(car,i){
let url=”http://127.0.0.1:3000/api/cars/edit/”+car.id
axios.get(url)
.then(data =>{
this.car=data.data.data;
.catch(err =>{
throw err;
save(){
if(this.car.id){
axios.put(“http://127.0.0.1:3000/api/cars”,app.car)
.then(respons =>{
if(respons.data.status===”ok”){
alert(“修改成功!”)
this.car.id=0;
this.car.name=””;
this.car.price=””;
this.car.speed=””;
this.car.color=””;
this.carInfo();
.catch(err =>{
throw err;
}else{
axios.post(“http://127.0.0.1:3000/api/cars”,this.car)
.then(respons =>{
if(respons.data.status===”ok”){
alert(“添加成功!”)
app.cars.push(respons.data.data)
this.car.id=0;
this.car.name=””;
this.car.price=””;
this.car.speed=””;
this.car.color=””;
this.carInfo();
.catch(err =>{
throw err;
created(){
this.carInfo();
Original: https://www.cnblogs.com/zsbb/p/16707173.html
Author: 最帅爸爸
Title: Node.js(四)json
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/616220/
转载文章受原作者版权保护。转载请注明原作者出处!