123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <template>
- <view
- class="tn-grid-class tn-grid"
- :style="{
- justifyContent: gridAlignStyle
- }"
- >
- <slot></slot>
- </view>
- </template>
- <script>
- export default {
- name: 'tn-grid',
- props: {
-
- col: {
- type: [Number, String],
- default: 3
- },
-
-
- align: {
- type: String,
- default: 'left'
- },
-
- hoverClass: {
- type: String,
- default: 'tn-hover'
- }
- },
- data() {
- return {
-
- }
- },
- watch: {
-
- parentData() {
- if (this.children.length) {
- this.children.map(child => {
-
- typeof(child.updateParentData) === 'function' && child.updateParentData()
- })
- }
- }
- },
- created() {
-
- this.children = []
- },
- computed: {
-
- parentData() {
- return [this.hoverClass, this.col, this.border]
- },
-
- gridAlignStyle() {
- switch(this.align) {
- case 'left':
- return 'flex-start'
- case 'center':
- return 'center'
- case 'right':
- return 'flex-end'
- default:
- return 'flex-start'
- }
- }
- },
- methods: {
- click(index) {
- this.$emit('click', index)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
-
- // 组件中兼容小程序的方式,不过不能使用对齐方式
- // .tn-grid {
- // width: 100%;
- // /* #ifdef MP */
- // position: relative;
- // box-sizing: border-box;
- // overflow: hidden;
- // /* #endif */
-
- // /* #ifndef MP */
- // /* #ifndef APP-NVUE */
- // display: flex;
- // flex-direction: row;
- // /* #endif */
- // flex-wrap: wrap;
- // align-items: center;
- // /* #endif */
- // }
-
- // 在使用组件时兼容小程序
- .tn-grid {
- width: 100%;
-
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- align-items: center;
- }
-
- </style>
|