🌐 AI搜索 & 代理 主页
Skip to content

Commit d40d3d9

Browse files
authored
Update collapse.js
1 parent 4f2ec40 commit d40d3d9

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/components/collapse/collapse.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Vue from '../../utils/vue'
2+
import idMixin from '../../mixins/id'
23
import listenOnRootMixin from '../../mixins/listen-on-root'
34
import normalizeSlotMixin from '../../mixins/normalize-slot'
45
import { isBrowser } from '../../utils/env'
@@ -32,16 +33,12 @@ const EventOptions = { passive: true, capture: false }
3233
// @vue/component
3334
export const BCollapse = /*#__PURE__*/ Vue.extend({
3435
name: 'BCollapse',
35-
mixins: [listenOnRootMixin, normalizeSlotMixin],
36+
mixins: [idMixin, listenOnRootMixin, normalizeSlotMixin],
3637
model: {
3738
prop: 'visible',
3839
event: 'input'
3940
},
4041
props: {
41-
id: {
42-
type: String,
43-
default: null
44-
},
4542
isNav: {
4643
type: Boolean,
4744
default: false
@@ -105,7 +102,7 @@ export const BCollapse = /*#__PURE__*/ Vue.extend({
105102
})
106103
// Listen for "Sync state" requests from `v-b-toggle`
107104
this.listenOnRoot(EVENT_STATE_REQUEST, id => {
108-
if (id === this.id) {
105+
if (id === this.safeId()) {
109106
this.$nextTick(this.emitSync)
110107
}
111108
})
@@ -174,17 +171,17 @@ export const BCollapse = /*#__PURE__*/ Vue.extend({
174171
emitState() {
175172
this.$emit('input', this.show)
176173
// Let v-b-toggle know the state of this collapse
177-
this.$root.$emit(EVENT_STATE, this.id, this.show)
174+
this.$root.$emit(EVENT_STATE, this.safeId(), this.show)
178175
if (this.accordion && this.show) {
179176
// Tell the other collapses in this accordion to close
180-
this.$root.$emit(EVENT_ACCORDION, this.id, this.accordion)
177+
this.$root.$emit(EVENT_ACCORDION, this.safeId(), this.accordion)
181178
}
182179
},
183180
emitSync() {
184181
// Emit a private event every time this component updates to ensure
185182
// the toggle button is in sync with the collapse's state
186183
// It is emitted regardless if the visible state changes
187-
this.$root.$emit(EVENT_STATE_SYNC, this.id, this.show)
184+
this.$root.$emit(EVENT_STATE_SYNC, this.safeId(), this.show)
188185
},
189186
checkDisplayBlock() {
190187
// Check to see if the collapse has `display: block !important;` set.
@@ -211,7 +208,7 @@ export const BCollapse = /*#__PURE__*/ Vue.extend({
211208
}
212209
},
213210
handleToggleEvt(target) {
214-
if (target !== this.id) {
211+
if (target !== this.safeId()) {
215212
return
216213
}
217214
this.toggle()
@@ -220,7 +217,7 @@ export const BCollapse = /*#__PURE__*/ Vue.extend({
220217
if (!this.accordion || accordion !== this.accordion) {
221218
return
222219
}
223-
if (openedId === this.id) {
220+
if (openedId === this.safeId()) {
224221
// Open this collapse if not shown
225222
if (!this.show) {
226223
this.toggle()
@@ -243,7 +240,7 @@ export const BCollapse = /*#__PURE__*/ Vue.extend({
243240
{
244241
class: this.classObject,
245242
directives: [{ name: 'show', value: this.show }],
246-
attrs: { id: this.id || null },
243+
attrs: { id: this.safeId() },
247244
on: { click: this.clickHandler }
248245
},
249246
[this.normalizeSlot('default')]

0 commit comments

Comments
 (0)