Cristiano Magro
10 days ago 9f20397f5fa48aa2ba0b48f47ebc3c853dfd1137
commit | author | age
a19e6e 1 <template>
326c8c 2   <form @submit.prevent="submitForm">
a19e6e 3     <div class="form-control">
CM 4       <label for="user-name">Your Name</label>
326c8c 5       <input id="user-name" name="user-name" type="text" v-model="userName" />
a19e6e 6     </div>
CM 7     <div class="form-control">
8       <label for="age">Your Age (Years)</label>
9f2039 9       <input id="age" name="age" type="number" v-model="userAge" ref="inputAge" />
a19e6e 10     </div>
CM 11     <div class="form-control">
12       <label for="referrer">How did you hear about us?</label>
9f2039 13       <select id="referrer" name="referrer" v-model="referrer">
a19e6e 14         <option value="google">Google</option>
CM 15         <option value="wom">Word of mouth</option>
16         <option value="newspaper">Newspaper</option>
17       </select>
18     </div>
19     <div class="form-control">
20       <h2>What are you interested in?</h2>
21       <div>
22         <input id="interest-news" name="interest" type="checkbox" />
23         <label for="interest-news">News</label>
24       </div>
25       <div>
26         <input id="interest-tutorials" name="interest" type="checkbox" />
27         <label for="interest-tutorials">Tutorials</label>
28       </div>
29       <div>
30         <input id="interest-nothing" name="interest" type="checkbox" />
31         <label for="interest-nothing">Nothing</label>
32       </div>
33     </div>
34     <div class="form-control">
35       <h2>How do you learn?</h2>
36       <div>
37         <input id="how-video" name="how" type="radio" />
38         <label for="how-video">Video Courses</label>
39       </div>
40       <div>
41         <input id="how-blogs" name="how" type="radio" />
42         <label for="how-blogs">Blogs</label>
43       </div>
44       <div>
45         <input id="how-other" name="how" type="radio" />
46         <label for="how-other">Other</label>
47       </div>
48     </div>
49     <div>
50       <button>Save Data</button>
51     </div>
52   </form>
53 </template>
54
326c8c 55 <script>
CM 56 export default {
57   data() {
58     return {
59       userName: '',
79dfa2 60       userAge: null,
9f2039 61       referrer: 'wom',
326c8c 62     }
CM 63   },
64   methods: {
65     submitForm() {
79dfa2 66       console.log('Username: ' + this.userName);
326c8c 67       this.userName = '';
9f2039 68       console.log('User age: ');
CM 69       console.log(this.userAge); //number
70       console.log(this.$refs.inputAge.value);  //string
71       console.log(18);
72
73       console.log('referrer: ' + this.referrer);
74       this.referrer = 'wom';
79dfa2 75
CM 76       this.userAge = null;
77     }
326c8c 78   }
CM 79
80 }
81 </script>
82
a19e6e 83 <style scoped>
CM 84 form {
85   margin: 2rem auto;
86   max-width: 40rem;
87   border-radius: 12px;
88   box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
89   padding: 2rem;
90   background-color: #ffffff;
91 }
92
93 .form-control {
94   margin: 0.5rem 0;
95 }
96
97 label {
98   font-weight: bold;
99 }
100
101 h2 {
102   font-size: 1rem;
103   margin: 0.5rem 0;
104 }
105
106 input,
107 select {
108   display: block;
109   width: 100%;
110   font: inherit;
111   margin-top: 0.5rem;
112 }
113
114 select {
115   width: auto;
116 }
117
118 input[type='checkbox'],
119 input[type='radio'] {
120   display: inline-block;
121   width: auto;
122   margin-right: 1rem;
123 }
124
326c8c 125 input[type='checkbox']+label,
CM 126 input[type='radio']+label {
a19e6e 127   font-weight: normal;
CM 128 }
129
130 button {
131   font: inherit;
132   border: 1px solid #0076bb;
133   background-color: #0076bb;
134   color: white;
135   cursor: pointer;
136   padding: 0.75rem 2rem;
137   border-radius: 30px;
138 }
139
140 button:hover,
141 button:active {
142   border-color: #002350;
143   background-color: #002350;
144 }
145 </style>