screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Js Select dynamic (multiple) elements</h3> <div v-for="(item, index) in items" :key="index" ref="itemRefs">{{item}}</div> <button @click="changeColor()">Change Color</button> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { items: ['Apple', 'Orange', 'Banana'], }; }, methods: { changeColor() { const itemRefs = this.$refs.itemRefs; // Get array of refs for (let i = 0; i < itemRefs.length; i++) { itemRefs[i].style.color = 'red'; // Change color of each element } }, } }); </script> <style scoped> #app { font-family: Arial, sans-serif; padding: 20px; background-color: #f2f2f2; } h3 { font-size: 24px; color: #333; } div { margin: 10px 0; padding: 10px; border: 1px solid #ccc; background-color: #fff; } button { padding: 10px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer; } button:hover { background-color: #0062cc; } </style> </body> </html>