svg使用 element plus 使用外部下载的svg,使用或作为背景图片的使用方式,svg背景填充自适应父级宽高

friger.vue

注意:引入路径后加#svgView(preserveAspectRatio(none)),可解决宽高设置无效的问题

代码上就这两句就行,它去这个路径下去找@/assets/svgs/login-bg.svg,往这个目录下放svg文件就行

<template>
    <div class="parent-container">
      
        <el-row  v-for="rindex of 4" :key="rindex" :id="rindex" :ref="rindex">
            <point v-for="cindex of 8" :key="cindex" :widthp="widthp" :heightp="heightp"  :sizep="sizep"  :color1="color1"  :color2="getpcolr2(rindex,cindex)"></point>
        </el-row>
    </div>
    
</template>

<script setup>
import point from './point.vue'
import { FullScreen, Document, Menu as IconMenu, Setting,HomeFilled,CirclePlusFilled } from '@element-plus/icons-vue'

// 定义props
const props = defineProps({
  widthp:{
    type: String,
    default:'30px'

  },
  heightp:{
    type: String,
    default:'30px'
  },
  sizep:{
    type: String,
    default:'22px'
  },
  color1:{
    type: String,
    default:'rgb(216, 216, 216)'
  },
  color2:{
    type: String,
    default:'rgb(0, 88, 165)'
  },
  colNum:{
    type: Number,
    default:'7'

  },
  rowNum:{
    type: Number,
    default:'7'
  },
  bandNo:{
    type: Number,
    default: 0
  },
  pData:{
    type: [Object],
    default: () => {
      return {}
    }
  }
});
import { reactive, ref, nextTick, defineProps,defineEmits,toRefs,watch,onMounted  } from 'vue'
const { widthp,heightp,fontSize,color1,color2,colNum,rowNum,pData,bandNo} = toRefs(props);


const getpcolr2 =(rindex,cindex) =>{
    console.log('pData ', pData.value)
    const seq = getCellSeq(rindex,cindex)
    const status = pData.value[bandNo.value][seq]['status']
    if(status == '1'){
       return 'rgb(0, 88, 165)'
    }else{
        return 'rgb(185, 0, 31)'
    }
    
}
const getCellSeq  = (rindex,cindex) =>{
  const cellSeq = (cindex-1 ) * rowNum.value + rindex 
 // console.log('我得到id cellSeq ',rindex,cindex, cellSeq)
   return cellSeq+''
}




</script>

<style lang="scss" scoped>

.parent-container {
  padding: 1.5%;
  display: inline-block;
  background-image: url('@/assets/svgs/full_screen_full.svg#svgView(preserveAspectRatio(none))');
  background-repeat:no-repeat;
  position: contain;
  background-size: 110% 100%;
  background-color: rgb(129, 132, 134);
}
.colort{
    color:rgb(216, 216, 216)
}

</style>

 point.vue

<template>
    <div class="p1" :style="{ backgroundColor:color1,width:widthp,height:heightp }">
        <el-icon class="p2"  :size="sizep" :style="{ color:color2 }"><CirclePlusFilled /></el-icon>
    </div>
  
</template>

<script setup>
import { PictureFilled, Document, Menu as IconMenu, Setting,HomeFilled,CirclePlusFilled } from '@element-plus/icons-vue'
import point from './point.vue'
// 定义props
const props = defineProps({
  widthp:{
    type: String,
    default:'20px'

  },
  heightp:{
    type: String,
    default:'20px'
  },
  sizep:{
    type: String,
    default:'18px'
  },
  color1:{
    type: String,
    default:'rgb(172, 172, 172,0.5)'
  },
  color2:{
    type: String,
    default:'rgb(0, 88, 165)'
  },
});
import { reactive, ref, nextTick, defineProps,defineEmits,toRefs,watch,onMounted  } from 'vue'
const { widthp,heightp,fontSize,color1,color2} = toRefs(props);

</script>

<style lang="scss" scoped>
.p1{
    // width: 20px;
    // height: 20px;
    position: relative;
  //  background-color: rgb(172, 172, 172,0.3);
    
}
.p2{

 //   color: rgb(0, 88, 165);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

}
</style>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值