首页 > 移动平台 > 详细

封装垂直和水平虚线(uniapp和vue均可)

时间:2021-07-22 11:06:52      阅读:60      评论:0      收藏:0      [点我收藏+]

根据项目需求封装~ 用到了linear-gradient

// 所用到参数
X              水平
Y              垂直
dash           虚线
solid          实线
color          颜色
"dash-width"   每条虚线宽度(px)

组件使用

<template>
  <dw-line dash X></dw-line>
</template>

<script>
import dwLine from "@/components/Line/dwLine";

export default{
  components: { dwLine }
}
</script>

组件代码(uniapp)

<template>
  <view v-if="dash" :style="style"></view>
  <view v-else-if="solid" :style="style"></view>
</template>

<script>
export default {
  props: {
    dash: {
      type: Boolean,
      default: false,
    },
    solid: {
      type: Boolean,
      default: false,
    },
    X: {
      type: Boolean,
      default: false,
    },
    Y: {
      type: Boolean,
      default: false,
    },
    color: {
      type: String,
      default: "#dfe6e9",
    },
    "dash-width": {
      type: String,
      default: "6",
    },
  },
  computed: {
    style() {
      const height = this.X ? "2px" : "100%";
      const width = this.Y ? "2px" : "100%";
      let background = "#fff";
      if (this.dash) {
        background = `linear-gradient(to ${this.Y ? "top" : "right"}, ${this.color}, ${this.color} ${this.dashWidth / 2}px, transparent ${this.dashWidth / 2}px, transparent);background-size: ${this.Y ? `100% ${this.dashWidth}px` : `${this.dashWidth}px 100%`}`;
      } else if (this.solid) {
        background = `${this.color}`;
      }
      return `height:${height};width:${width};background:${background}`;
    },
  },
};
</script>

<style lang="scss" scoped></style>

 

封装垂直和水平虚线(uniapp和vue均可)

原文:https://www.cnblogs.com/HDWdemo/p/15042685.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!