Checkbox - 图1

Checkbox Vue Component

Checkbox Vue component represents Checkbox component.

Checkbox Components

There are following components included:

  • f7-checkbox

Checkbox Properties

Prop Type Default Description
<f7-checkbox> properties
--- --- --- ---
checked boolean Defines whether the checkbox input is checked or not
indeterminate boolean Defines whether the checkbox input is in indeterminate state or not
name string number Checkbox input name
value string number boolean Checkbox input value
disabled boolean Defines whether the checkbox input is disabled
readonly boolean Defines whether the checkbox input is readonly

Checkbox Events

Event Description
<f7-checkbox> events
--- ---
change Event 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>, <f7-list-item>.

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>

6. <!-- With array value -->
7. <f7-checkbox
8. value="banana"
9. :checked="fruits.indexOf('banana') >= 0"
10. @change="checkFruits"
11. ></f7-checkbox>

13. <f7-checkbox
14. value="orange"
15. :checked="fruits.indexOf('orange') >= 0"
16. @change="checkFruits"
17. ></f7-checkbox>

19. <f7-checkbox
20. value="apple"
21. :checked="fruits.indexOf('apple') >= 0"
22. @change="checkFruits"
23. ></f7-checkbox>
24. </f7-page>
25. </template>
26. <script>
27. export default {
28. data() {
29. return {
30. jobIsDone: false,
31. fruits: [],
32. };
33. },
34. methods: {
35. checkFruits(event) {
36. const self = this;
37. const value = event.target.value;
38. if (event.target.checked) {
39. self.fruits.push(value);
40. } else {
41. self.fruits.splice(self.fruits.indexOf(value), 1);
42. }
43. },
44. },
45. };
46. </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>

← Cards

Chips / Tags →