screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h2>Vue js check date existence</h2> <input type="date" v-model="inputDate" /> <button @click="checkDate">Check Date</button> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { inputDate: "2023-06-27", dateArray: [ new Date("2023-06-25"), new Date("2023-06-26"), new Date("2023-06-27"), new Date("2023-06-28"), ], isDateContained: false, }; }, methods: { checkDate() { const selectedDate = new Date(this.inputDate); this.isDateContained = this.dateArray.some((date) => this.areDatesEqual(date, selectedDate) ); if (this.isDateContained) { alert("The date is contained in the array."); } else { alert("The date is not contained in the array."); } }, areDatesEqual(date1, date2) { return ( date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate() ); }, }, }); </script> <style> #app { margin: 0 auto; width: 600px; text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding:20pxF } </style> </body> </html>