美文网首页
vue3 通过props接收,动态变量传入scss中,运用:cs

vue3 通过props接收,动态变量传入scss中,运用:cs

作者: 冰落寞成 | 来源:发表于2023-05-21 16:08 被阅读0次

    自定义九宫格样式,需要用户传递一个列数,来显示九宫格一行显示几列

    <template>
      <div class="panel-container"
        :style="{'--column-num':props.columnNum}">
        <template v-if="list.length>0">
          <template v-for="(item,index) in list" :key="index">
            <div class="panel-item">
              <div class="panel-item-num">{{item[defaulConfig.num]}}</div>
              <div class="panel-item-text">{{item[defaulConfig.text]}}</div>
            </div>
          </template>
        </template>
      </div>
    </template>
    <script setup>
    import { ref } from 'vue'
    import { deepAssign } from '@/utils'
    const props = defineProps({
      columnNum: {
        type: Number,
        default: () => 2
      },
      defaultProps: {
        type: Object,
        default: () => {}
      }
    })
    const defaulConfig = ref({
      num: 'num',
      text: 'text'
    })
    defaulConfig.value = deepAssign(defaulConfig.value, props.defaultProps)
    
    const list = ref([])
    const setData = (data = []) => {
      list.value = data
    }
    defineExpose({
      setData
    })
    </script>
    <style lang="scss" scoped>
      .panel-container{
        background: #fff;
        border-radius: 6px;
        padding:20px;
        @include flexLayout($vertical:center,$horizontal:flex-start,$wrap:wrap);
        .panel-item{
          width:calc(100%/var(--column-num));
        }
      }
    </style>
    
    

    相关文章

      网友评论

          本文标题:vue3 通过props接收,动态变量传入scss中,运用:cs

          本文链接:https://www.haomeiwen.com/subject/awoasdtx.html