| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import { VantComponent } from '../common/component';
- VantComponent({
- relation: {
- name: 'collapse-item',
- type: 'descendant',
- linked: function linked(child) {
- this.set({
- items: this.data.items.concat([child])
- }, function () {
- child.updateExpanded();
- });
- }
- },
- props: {
- accordion: Boolean,
- value: null
- },
- data: {
- items: []
- },
- watch: {
- value: function value() {
- this.data.items.forEach(function (child) {
- child.updateExpanded();
- });
- },
- accordion: function accordion() {
- this.data.items.forEach(function (child) {
- child.updateExpanded();
- });
- }
- },
- methods: {
- switch: function _switch(name, expanded) {
- var _this$data = this.data,
- accordion = _this$data.accordion,
- value = _this$data.value;
- if (!accordion) {
- name = expanded ? value.concat(name) : value.filter(function (activeName) {
- return activeName !== name;
- });
- } else {
- name = expanded ? name : '';
- }
- this.$emit('change', name);
- this.$emit('input', name);
- }
- }
- });
|