npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

v-coupon

v0.3.8

Published

a coupon component for vue

Downloads

10

Readme

v-coupon 一款基于 vue 的卡券组件

介绍

你是否在心里暗骂设计师设计出这种有缺口的卡券?

你是否试了多种 CSS 方案都无法完美实现?

你是否在为不得不用 jpg/png...等格式而内心挣扎?

v-coupon 就是为了解决以上痛点而诞生的。

先看看效果

如果上图你有看到白色背景,那不是 bug, 是我截图的时候页面的背景就是白色的

使用

  1. 安装
npm i v-coupon
  1. 在你的 vue 入口文件注册
import coupon from 'v-coupon'
Vue.use(coupon)
  1. 在需要展示卡券的页面使用
<v-coupon config="yourConfig">
  <div class="content">
    你要展示的内容
  </div>
</v-coupon>

当然,你也许不需要全局引入,可以直接在需要使用的页面注册 v-coupon/src/coupon.vue 组件

import vCoupon from 'v-coupon/src/coupon.vue'

// ...省略其他无关代码

components: {
    'v-coupon': vCoupon
}

详细说明

  1. <v-coupon>...</v-coupon> 之间包含的内容,是一个 slot, 这意味这 v-coupon 只提供一个裁切模版,其他内容你可以任意定制,给予你最大的发挥空间,但同时为了避免各种复杂的问题,只能有一个slot, 以下代码的第二个 div 不会被显示出来
<v-coupon config="yourConfig">
  <div class="content">
    第一个 div 的内容,会正常显示
  </div>

  <div>
    第二个 div 的内容,不会显示出来
  </div>
</v-coupon>
  1. 配置, 上例的 yourConfig 就是我们要传给 v-coupon 的配置,具体的配置项如下
{
    width: 200, // 卡券宽度
    height: 300, // 卡券高度
    borderRadius: 15, // 卡券四个角的圆角半径
    borderColor: '#33cc44', // 边框颜色
    borderWidth: 0.5, // 边框粗细
    borderOpcity: 1, // 边框透明度
    borderDash: null, // 边框虚线数组, 直线是 null, 虚线的话给一个数组,如[2,2]
    showLine: true, // 是否显示分割线
    lineColor: '#33cc44', // 分割线颜色
    lineWidth: 0.4, // 分割线粗细
    lineOpcity: 1, // 分割线透明度
    lineDash: [3, 5], // 分割线虚线数组, 同 边框虚线数组
    lineOffset: 5, // 分割线跟卡券两侧的距离, 为 0 则相连
    cutPosition: 200, // 裁切口的位置
    cutRadius: 10, // 裁切口的半径
    cutSlope: 1.5, // 裁切口的弧度
    background: '#ffffff' // 背景颜色, 优先级低于 slot 的背景
}

以上单位, 除了裁切口弧度 cutSlope 外,其他数值的单位均为 px, 暂未对其他单位做支持.

上面的配置的值, 其实就是 v-coupon 的默认值, 采用 Object.assign 的方式合并用户配置默认值, 也就是说, 你不必传所有的配置,没有传的会采用默认值

边框虚线数组 和 分割线虚线数组 有不明白的, 可以参考 MDN:SGV的stroke-dasharray属性

兼容

v-coupon 的核心内容是 SVG 的 foreignObject, 具体的兼容请参考 Can I Use

其他

有任何 bug, 需求, 意见, 建议, 吐槽, 欢迎走 issue 通道, 同时也欢迎 pr.