Checkbox - 图1

Checkbox Vue Component

Checkbox Vue component represents Checkbox component.

Checkbox Components

There are following components included:

  • **f7-checkbox**

Checkbox Properties

PropTypeDefaultDescription
<f7-checkbox> properties
checkedbooleanDefines whether the checkbox input is checked or not
namestring
number
Checkbox input name
valuestring
number
boolean
Checkbox input value
disabledbooleanDefines whether the checkbox input is disabled
readonlybooleanDefines whether the checkbox input is readonly

Checkbox Events

EventDescription
<f7-checkbox> events
changeEvent will be triggered when checkbox state changed

Checkboxes List

Checkboxes List is not a separate component, but just a particular case of using [<f7-list>]($9b027097947ca6d7.md), [<f7-list-item>]($acf7bf2b27ac6164.md).

  1. <f7-list>
  2. <!-- Additional "checkbox" prop to enable checkbox list item -->
  3. <f7-list-item checkbox value="check_1" checked title="Checkbox 1"></f7-list-item>
  4. <f7-list-item checkbox value="check_2" title="Checkbox 2"></f7-list-item>
  5. </f7-list>

Checkbox v-model

v-model is not supported on Checkbox vue component. Instead, just use the combination of checked property and @change event:

  1. <template>
  2. <!-- With boolean value -->
  3. <f7-checkbox :checked="jobIsDone" @change="jobIsDone = $event.target.checked"></f7-checkbox>
  4. <!-- With array value -->
  5. <f7-checkbox
  6. value="banana"
  7. :checked="fruits.indexOf('banana') >= 0"
  8. @change="checkFruits"
  9. ></f7-checkbox>
  10. <f7-checkbox
  11. value="orange"
  12. :checked="fruits.indexOf('orange') >= 0"
  13. @change="checkFruits"
  14. ></f7-checkbox>
  15. <f7-checkbox
  16. value="apple"
  17. :checked="fruits.indexOf('apple') >= 0"
  18. @change="checkFruits"
  19. ></f7-checkbox>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. jobIsDone: false,
  26. fruits: [],
  27. };
  28. },
  29. methods: {
  30. checkFruits(event) {
  31. const self = this;
  32. const value = event.target.value;
  33. if (event.target.checked) {
  34. self.fruits.push(value);
  35. } else {
  36. self.fruits.splice(self.fruits.indexOf(value), 1);
  37. }
  38. },
  39. },
  40. };
  41. </script>

Examples

  1. <f7-block-title>Inline</f7-block-title>
  2. <f7-block strong>
  3. <p>Lorem <f7-checkbox name="checkbox-1"></f7-checkbox> ipsum dolor sit amet, consectetur adipisicing elit. Alias beatae illo nihil aut eius commodi sint eveniet aliquid eligendi <f7-checkbox name="checkbox-2" checked></f7-checkbox> ad delectus impedit tempore nemo, enim vel praesentium consequatur nulla mollitia!</p>
  4. </f7-block>
  5. <f7-block-title>Checkbox Group</f7-block-title>
  6. <f7-list>
  7. <f7-list-item checkbox title="Books" name="demo-checkbox" checked></f7-list-item>
  8. <f7-list-item checkbox title="Movies" name="demo-checkbox"></f7-list-item>
  9. <f7-list-item checkbox title="Food" name="demo-checkbox"></f7-list-item>
  10. <f7-list-item checkbox title="Drinks" name="demo-checkbox"></f7-list-item>
  11. </f7-list>
  12. <f7-block-title>With Media Lists</f7-block-title>
  13. <f7-list media-list>
  14. <f7-list-item
  15. checkbox
  16. checked
  17. name="demo-media-checkbox"
  18. title="Facebook"
  19. after="17:14"
  20. subtitle="New messages from John Doe"
  21. text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
  22. ></f7-list-item>
  23. <f7-list-item
  24. checkbox
  25. name="demo-media-checkbox"
  26. title="John Doe (via Twitter)"
  27. after="17:11"
  28. subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
  29. text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
  30. ></f7-list-item>
  31. <f7-list-item
  32. checkbox
  33. name="demo-media-checkbox"
  34. title="Facebook"
  35. after="16:48"
  36. subtitle="New messages from John Doe"
  37. text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
  38. ></f7-list-item>
  39. <f7-list-item
  40. checkbox
  41. name="demo-media-checkbox"
  42. title="John Doe (via Twitter)"
  43. after="15:32"
  44. subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
  45. text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
  46. ></f7-list-item>
  47. </f7-list>