123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <template>
-
- <cell ref="u-index-item">
-
- <view
- class="u-index-item"
- :id="`u-index-item-${id}`"
- :class="[`u-index-item-${id}`]"
- >
- <slot />
- </view>
-
- </cell>
-
- </template>
- <script>
- import props from './props.js';
-
-
- const dom = uni.requireNativePlugin('dom')
-
-
- export default {
- name: 'u-index-item',
- mixins: [uni.$u.mpMixin, uni.$u.mixin,props],
- data() {
- return {
-
- top: 0,
- height: 0,
- id: ''
- }
- },
- created() {
-
- this.anchor = {}
- },
- mounted() {
- this.init()
- },
- methods: {
- init() {
-
- this.getParentData('u-index-list')
- if (!this.parent) {
- return uni.$u.error('u-index-item必须要搭配u-index-list组件使用')
- }
- uni.$u.sleep().then(() =>{
- this.getIndexItemRect().then(size => {
-
- this.top = Math.ceil(size.top)
- this.height = Math.ceil(size.height)
- })
- })
- },
- getIndexItemRect() {
- return new Promise(resolve => {
-
- this.$uGetRect('.u-index-item').then(size => {
- resolve(size)
- })
-
-
- const ref = this.$refs['u-index-item']
- dom.getComponentRect(ref, res => {
- resolve(res.size)
- })
-
- })
- }
- },
- }
- </script>
- <style lang="scss" scoped>
- @import "../../libs/css/components.scss";
-
- </style>
|