| | |
| | | <template> |
| | | <form> |
| | | <form @submit.prevent="submitForm"> |
| | | <div class="form-control"> |
| | | <label for="user-name">Your Name</label> |
| | | <input id="user-name" name="user-name" type="text" /> |
| | | <input id="user-name" name="user-name" type="text" v-model="userName" /> |
| | | </div> |
| | | <div class="form-control"> |
| | | <label for="age">Your Age (Years)</label> |
| | | <input id="age" name="age" type="number" /> |
| | | <input id="age" name="age" type="number" v-model="userAge" ref="inputAge" /> |
| | | </div> |
| | | <div class="form-control"> |
| | | <label for="referrer">How did you hear about us?</label> |
| | | <select id="referrer" name="referrer"> |
| | | <select id="referrer" name="referrer" v-model="referrer"> |
| | | <option value="google">Google</option> |
| | | <option value="wom">Word of mouth</option> |
| | | <option value="newspaper">Newspaper</option> |
| | |
| | | </div> |
| | | </form> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | data() { |
| | | return { |
| | | userName: '', |
| | | userAge: null, |
| | | referrer: 'wom', |
| | | } |
| | | }, |
| | | methods: { |
| | | submitForm() { |
| | | console.log('Username: ' + this.userName); |
| | | this.userName = ''; |
| | | console.log('User age: '); |
| | | console.log(this.userAge); //number |
| | | console.log(this.$refs.inputAge.value); //string |
| | | console.log(18); |
| | | |
| | | console.log('referrer: ' + this.referrer); |
| | | this.referrer = 'wom'; |
| | | |
| | | this.userAge = null; |
| | | } |
| | | } |
| | | |
| | | } |
| | | </script> |
| | | |
| | | <style scoped> |
| | | form { |
| | |
| | | margin-right: 1rem; |
| | | } |
| | | |
| | | input[type='checkbox'] + label, |
| | | input[type='radio'] + label { |
| | | input[type='checkbox']+label, |
| | | input[type='radio']+label { |
| | | font-weight: normal; |
| | | } |
| | | |