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 Get Selected Option Value from Dropdown</h3> <label for="my-dropdown">Select a fruit:</label> <select id="my-dropdown" v-model="selectedFruit"> <option disabled value="">Please select one</option> <option v-for="(fruit, index) in fruits" :key="index" :value="fruit.value">{{ fruit.label }}</option> </select> <p>The selected fruit is: {{ selectedFruit }}</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { selectedFruit: '', fruits: [ { label: 'Apple', value: 'apple' }, { label: 'Banana', value: 'banana' }, { label: 'Cherry', value: 'cherry' }, { label: 'Date', value: 'date' }, { label: 'Elderberry', value: 'elderberry' } ] }; } }) </script> <style> #app { display: flex; flex-direction: column; align-items: center; font-family: Arial, sans-serif; padding: 20px; } label { margin-bottom: 10px; } select { font-size: 16px; padding: 10px; border-radius: 5px; border: 1px solid #ccc; margin-bottom: 20px; } option[disabled] { color: #999; } p { font-size: 18px; font-weight: bold; } </style> </body> </html>