screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> </head> <body> <div id="app"> <h3>Vue Get Element Property</h3> <div ref="my-element">fontawesomeicons.com</div> <pre>Color:{{color}}</pre> <pre>bgColor:{{bgColor}}</pre> <pre>Font Size:{{fontSize}}</pre> <pre>Paading:{{padding}}</pre> <pre>margin:{{margin}}</pre> <pre>Border Radius:{{borderRadius}}</pre> </div> <script type="module"> const app = Vue.createApp({ data() { return { color: '', bgColor: '', fontSize: '', padding: '', margin: '', borderRadius: '' } }, mounted() { const myElement = this.$refs['my-element']; // get the computed style of the element const elementStyle = window.getComputedStyle(myElement); console.log(elementStyle) // get the values of multiple properties this.color = elementStyle.getPropertyValue('color'); this.bgColor = elementStyle.getPropertyValue('background-color'); this.fontSize = elementStyle.getPropertyValue('font-size'); this.padding = elementStyle.getPropertyValue('padding'); this.margin = elementStyle.getPropertyValue('margin'); this.borderRadius = elementStyle.getPropertyValue('border-radius'); } }) app.mount('#app') </script> <style scoped> #app { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } #app div { background-color: #f2f2f2; border-radius: 0.5rem; padding: 1rem; color: blue; font-size: 20px; margin: 1rem; } pre { font-size: 1.2rem; color: #333; background-color: #f7f7f7; padding: 0.5rem; margin: 0.5rem; border-radius: 5px; } </style> </body> </html>