screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Js get middle element from array</h3> <p>Array: {{ myArray }}</p> <p>Middle Item: {{ middleItem }}</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { myArray: [1, 2, 3, 4, 5, 6, 7,], middleItem: null }; }, mounted() { const middleIndex = Math.floor(this.myArray.length / 2); this.middleItem = this.myArray[middleIndex]; } }); </script> <style scoped> #app { margin: 20px; padding: 10px; border: 1px solid #ccc; background-color: #f7f7f7; text-align: center; } h3 { color: #333; font-size: 1.2em; margin-bottom: 10px; } p { margin: 10px 0; color: #555; line-height: 1.5; } </style> </body> </html>