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

Examples

Inline

  1. <f7-block strong>
  2. <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>
  3. </f7-block>

Checkbox Group

  1. <f7-list>
  2. <f7-list-item checkbox title="Books" name="demo-checkbox" checked></f7-list-item>
  3. <f7-list-item checkbox title="Movies" name="demo-checkbox"></f7-list-item>
  4. <f7-list-item checkbox title="Food" name="demo-checkbox"></f7-list-item>
  5. <f7-list-item checkbox title="Drinks" name="demo-checkbox"></f7-list-item>
  6. </f7-list>

Indeterminate State

  1. <f7-list>
  2. <f7-list-item
  3. checkbox
  4. title="Movies"
  5. name="demo-checkbox"
  6. :checked="movies.length === 2"
  7. :indeterminate="movies.length === 1"
  8. @change="onMoviesChange"
  9. >
  10. <ul slot="root">
  11. <f7-list-item
  12. checkbox
  13. title="Movie 1"
  14. name="demo-checkbox"
  15. value="Movie 1"
  16. :checked="movies.indexOf('Movie 1') >= 0"
  17. @change="onMovieChange"
  18. />
  19. <f7-list-item
  20. checkbox
  21. title="Movie 2"
  22. name="demo-checkbox"
  23. value="Movie 2"
  24. :checked="movies.indexOf('Movie 2') >= 0"
  25. @change="onMovieChange"
  26. />
  27. </ul>
  28. </f7-list-item>
  29. </f7-list>
  1. export default {
  2. data: function () {
  3. return {
  4. movies: ['Movie 1'],
  5. };
  6. },
  7. methods: {
  8. onMovieChange: function (e) {
  9. var self = this;
  10. var value = e.target.value;
  11. var movies = self.movies;
  12. if (e.target.checked) {
  13. movies.push(value);
  14. } else {
  15. movies.splice(movies.indexOf(value), 1);
  16. }
  17. },
  18. onMoviesChange: function (e) {
  19. var self = this;
  20. var movies = self.movies;
  21. if (movies.length === 1 || movies.length === 0) {
  22. self.movies = ['Movie 1', 'Movie 2'];
  23. } else if (movies.length === 2) {
  24. self.movies = [];
  25. }
  26. },
  27. }
  28. };

With Media Lists

  1. <f7-list media-list>
  2. <f7-list-item
  3. checkbox
  4. checked
  5. name="demo-media-checkbox"
  6. title="Facebook"
  7. after="17:14"
  8. subtitle="New messages from John Doe"
  9. 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."
  10. ></f7-list-item>
  11. <f7-list-item
  12. checkbox
  13. name="demo-media-checkbox"
  14. title="John Doe (via Twitter)"
  15. after="17:11"
  16. subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
  17. 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."
  18. ></f7-list-item>
  19. <f7-list-item
  20. checkbox
  21. name="demo-media-checkbox"
  22. title="Facebook"
  23. after="16:48"
  24. subtitle="New messages from John Doe"
  25. 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."
  26. ></f7-list-item>
  27. <f7-list-item
  28. checkbox
  29. name="demo-media-checkbox"
  30. title="John Doe (via Twitter)"
  31. after="15:32"
  32. subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
  33. 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."
  34. ></f7-list-item>
  35. </f7-list>