app-order-time.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <text>{{html}}</text>
  3. </template>
  4. <script>
  5. export default {
  6. name: "app-order-time",
  7. props: {
  8. time: String,
  9. },
  10. data() {
  11. return {
  12. html: '',
  13. t: null,
  14. }
  15. },
  16. watch: {
  17. time: {
  18. handler: function(data) {
  19. clearInterval(this.t);
  20. let timelog = new Date(data.replace(/-/g, '/'));
  21. let time = timelog.getTime() - new Date().getTime();
  22. let day = parseInt((time/1000/60/60/24)%30);
  23. let hou = parseInt((time/1000/60/60)%24);
  24. let min = parseInt((time/1000/60)%60);
  25. let sec = parseInt((time/1000)%60);
  26. if (day > 0) {
  27. this.html = day+"天"+hou+"小时"+(min<10?"0"+min:min) + "分"+(sec<10?"0"+sec:sec) + '秒';
  28. } else {
  29. this.html = hou+"小时"+(min<10?"0"+min:min) + "分"+(sec<10?"0"+sec:sec) + '秒';
  30. }
  31. this.t = setInterval(() =>{
  32. let time = timelog.getTime() - new Date().getTime();
  33. if (time < 0) {
  34. clearInterval(this.t);
  35. }
  36. let day = parseInt((time/1000/60/60/24)%30);
  37. let hou = parseInt((time/1000/60/60)%24);
  38. let min = parseInt((time/1000/60)%60);
  39. let sec = parseInt((time/1000)%60);
  40. if (day > 0) {
  41. this.html = day+"天"+hou+"小时"+(min<10?"0"+min:min) + "分"+(sec<10?"0"+sec:sec) + '秒';
  42. } else {
  43. this.html = hou+"小时"+(min<10?"0"+min:min) + "分"+(sec<10?"0"+sec:sec) + '秒';
  44. }
  45. },1000);
  46. },
  47. immediate: true,
  48. }
  49. },
  50. }
  51. </script>
  52. <style scoped>
  53. </style>