Building a Custom Control Component
1 files added
1 files modified
New file |
| | |
| | | <template> |
| | | <ul> |
| | | <li :class="{ active: activeOption === 'poor' }"> |
| | | <button type="button" @click="activate('poor')">Poor</button> |
| | | </li> |
| | | <li :class="{ active: activeOption === 'average' }"> |
| | | <button type="button" @click="activate('average')">Average</button> |
| | | </li> |
| | | <li :class="{ active: activeOption === 'great' }"> |
| | | <button type="button" @click="activate('great')">Great</button> |
| | | </li> |
| | | </ul> |
| | | </template> |
| | | |
| | | <script>export default { |
| | | data() { |
| | | return { |
| | | activeOption: null, |
| | | }; |
| | | }, |
| | | methods: { |
| | | activate(option) { |
| | | this.activeOption = option; |
| | | } |
| | | } |
| | | |
| | | } |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .active { |
| | | border-color: purple; |
| | | } |
| | | |
| | | .active button { |
| | | color: purple; |
| | | } |
| | | |
| | | ul { |
| | | list-style: none; |
| | | margin: 0.5rem 0; |
| | | padding: 0; |
| | | display: flex; |
| | | } |
| | | |
| | | li { |
| | | margin: 0 1rem; |
| | | border: 1px solid #ccc; |
| | | padding: 1rem; |
| | | display: flex; |
| | | align-items: center; |
| | | } |
| | | |
| | | button { |
| | | font: inherit; |
| | | border: none; |
| | | background-color: transparent; |
| | | cursor: pointer; |
| | | } |
| | | </style> |
| | |
| | | <label for="how-other">Other</label> |
| | | </div> |
| | | </div> |
| | | |
| | | <div class="form-control"> |
| | | <rating-control> |
| | | |
| | | </rating-control> |
| | | </div> |
| | | |
| | | <div class="form-control"> |
| | | <input type="checkbox" id="confirm-terms" name="confirm-terms" v-model="confirm"> |
| | | <label for="confirm-terms">Agree to terms of use?</label> |
| | |
| | | </template> |
| | | |
| | | <script> |
| | | import RatingControl from './RatingControl.vue'; |
| | | |
| | | export default { |
| | | components: { |
| | | RatingControl, |
| | | }, |
| | | data() { |
| | | return { |
| | | userName: '', |
| | |
| | | .form-control.invalid input{ |
| | | border-color: red; |
| | | } |
| | | |
| | | .form-control.invalid label{ |
| | | color: red; |
| | | } |