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
| watch: { status: function() { console.log(this.status);
if (this.resCarId === this.carId) { if (this.status === -1) { console.log("未预约"); this.backgroundcolor = "#FFFFFF"; } else if (this.status === 0) { console.log("已预约"); this.backgroundcolor = "#00CD00"; } else if (this.status === 1) { console.log("已停车"); this.backgroundcolor = "#FF0000"; } else { console.log("数据库错误"); this.backgroundcolor = "#030303"; } } } },
mounted() { const that = this; that.timer = setInterval(() => { axios .post("http://localhost:8090/smartparking/status", {carId: that.carId} ) .then(function(response) { that.status = response.data[0].status; that.resCarId = response.data[0].carId; }) .catch(function(error) { console.log(error); }); }, 2000); }, beforeDestroy() { window.clearInterval(this.timer); } }
|