提交 d9871b8e 编写于 作者: A AmyFoxFN

<update>(index-list): calculate subTitleHeight when data changed + speed defaul 0

上级 1694c6bd
......@@ -63,12 +63,81 @@
}
```
- Custom item content
Beside default usage, you could customise the content of each item as required by inserting your custom DOM into the slot of `cube-index-list-item` as shown below. And please don't modify the usage of `cube-index-list-group` and `cube-index-list-item` unless you really know what you are doing.
```html
<cube-index-list :data="cityData">
<cube-index-list-group
v-for="(group, index) in cityData"
:key="index"
:group="group">
<cube-index-list-item
v-for="(item, index) in group.items"
:key="index"
:item="item"
@select="selectItem">
<div class="custom-item">I am the custom {{item.name}}</div>
</cube-index-list-item>
</cube-index-list-group>
</cube-index-list>
```
```javascript
export default {
data() {
return {
cityData: cityData
}
},
methods: {
selectItem(item) {
console.log(item.name)
},
clickTitle(title) {
console.log(title)
}
}
}
```
```stylus
// Style of the custom item.
.custom-item
position: relative
height: 70px
line-height: 70px
padding: 0 16px
font-size: $fontsize-medium
// Use custom style to cover default style.
.cube-index-list-content
background-color: #222
color: #909090
.cube-index-list-anchor
background-color: #333
height: 30px
line-height: 30px
padding: 0 0 0 20px
.cube-index-list-nav
padding: 20px 0
border-radius: 10px
background: rgba(0,0,0,.3)
>ul
>li
padding: 3px
font-size: 12px
color: #909090
&.active
color: #ffcd32
```
### Props configuration
| Attribute | Description | Type | Default |
| - | - | - | - |
| title | title | String | - |
| data | data to be displayed | Array | [] |
| speed | when click the navigator, the transition time of scrolling to the specific anchor (unit: ms). | number | 0 |
- `data` sub configuration
......
......@@ -62,14 +62,14 @@
}
}
```
- 自定义插槽
除了默认结构,你还可以根据自己的需要自定义每一项的内容。如下所示,将你的自定义内容项填入`cube-index-list-item`的插槽。除非你真的知道自己在做什么,否则不要修改`cube-index-list-group``cube-index-list-item`的用法。
```html
<cube-index-list :data="cityData">
<cube-index-list-group
<cube-index-list-group
v-for="(group, index) in cityData"
:key="index"
:group="group">
......@@ -108,7 +108,7 @@
line-height: 70px
padding: 0 16px
font-size: $fontsize-medium
// 用自定义样式,覆写内置的默认样式
.cube-index-list-content
background-color: #222
......@@ -137,7 +137,7 @@
| - | - | - | - |
| title | 标题 | String | - |
| data | 需要展示的数据 | Array | [] |
| speed | 点击导航栏索引时,滚动到相应位置的动画时间(单位:ms) | number | 300 |
| speed | 点击导航栏索引时,滚动到相应位置的动画时间(单位:ms) | number | 0 |
- `data` 子配置项
......
......@@ -61,7 +61,7 @@
},
speed: {
type: Number,
default: 300
default: 0
}
},
data() {
......@@ -85,9 +85,6 @@
mounted() {
this.$nextTick(() => {
this.titleHeight = this.title && this.$refs.title ? getRect(this.$refs.title).height : 0
const subTitleEl = this.$el.querySelector('.cube-index-list-anchor')
this.subTitleHeight = subTitleEl ? getRect(subTitleEl).height : 0
this._calculateHeight()
})
},
......@@ -136,12 +133,14 @@
},
_calculateHeight() {
this.groupList = this.$el.getElementsByClassName('cube-index-list-group')
const subTitleEl = this.$el.getElementsByClassName('cube-index-list-anchor')[0]
this.subTitleHeight = subTitleEl ? getRect(subTitleEl).height : 0
this.listHeight = []
if (!this.groupList) {
return
}
this.listHeight = []
let height = this.titleHeight
this.listHeight.push(height)
for (let i = 0; i < this.groupList.length; i++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册