Skip to content

Commit 10617d6

Browse files
committed
Add public methods
1 parent 3f5f2e0 commit 10617d6

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/index.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,35 @@ const VirtualList = Vue.component(NAME, {
6868
mounted () {
6969
// set position.
7070
if (this.start) {
71-
this.setScrollOffset(this.virtual.getOffset(this.start))
71+
this.scrollToIndex(this.start)
7272
} else if (this.offset) {
73-
this.setScrollOffset(this.offset)
73+
this.scrollToOffset(this.offset)
7474
}
75+
76+
window.virtual = this.virtual
7577
},
7678

7779
methods: {
80+
// set current scroll position to a expectant offset.
81+
scrollToOffset (offset) {
82+
const { root } = this.$refs
83+
if (root) {
84+
root[this.directionKey] = offset || 0
85+
}
86+
},
87+
88+
// set current scroll position to a expectant index.
89+
scrollToIndex (index) {
90+
const offset = this.virtual.getOffset(index)
91+
this.scrollToOffset(offset)
92+
},
93+
94+
// ----------- public method end. -----------
95+
96+
getUniqueIdFromDataSources () {
97+
return this.dataSources.map((dataSource) => dataSource[this.dataKey])
98+
},
99+
78100
// event called when every item mounted or size changed.
79101
onItemResized (id, size) {
80102
this.virtual.saveSize(id, size)
@@ -117,18 +139,6 @@ const VirtualList = Vue.component(NAME, {
117139
this.emitEvent(offset, offsetShape, scrollShape, evt)
118140
},
119141

120-
getUniqueIdFromDataSources () {
121-
return this.dataSources.map((dataSource) => dataSource[this.dataKey])
122-
},
123-
124-
// set current scroll position to a expectant offset.
125-
setScrollOffset (offset) {
126-
const { root } = this.$refs
127-
if (root) {
128-
root[this.directionKey] = offset || 0
129-
}
130-
},
131-
132142
// emit event in special position.
133143
emitEvent (offset, offsetShape, scrollShape, evt) {
134144
const range = this.virtual.getRange()

0 commit comments

Comments
 (0)