vue.js - 在 Vue 中使用 Stripe 时如何应用自定义字体?vue-stripe-elements-plus
问题描述
我正在使用vue-stripe-elements-plus NPM 模块,但看不到如何添加自定义字体?
解决方案
这个插件使用你传递给你创建的第一个元素的选项来创建 VUE 元素。
当 Stripe创建元素时,它会将样式对象传递给样式选项。
它将elements
属性传递给 Stripe 的元素函数。
在这里您可以添加一个CustomFontSource对象。
请注意,如本例所示,如果您想使用 Google 字体,则必须转到提供的 URL 并在 @fontface 描述符中获取 URL。您可能会更好地自己托管字体,因为我担心这些 URL 可能会随着时间而改变。
stripeOptions: {
elements: {
fonts: [{
family: 'Lexend Deca',
src: 'url(https://fonts.gstatic.com/s/lexenddeca/v1/K2F1fZFYk-dHSE0UPPuwQ5qnJy_YZ2ON.woff2)',
unicodeRange: 'U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD',
style: 'normal',
weight: '400',
display: 'swap',
}],
},
style: {
base: {
color: 'red',
fontFamily: '"Lexend Deca", sans-serif',
fontSize: '18px',
fontWeight: '400',
fontSmoothing: 'antialiased',
},
},
},
条带组件:
<card-number
:stripe="stripeId"
:options="stripeOptions"
/>
<card-expiry
:stripe="stripeId"
:options="stripeOptions"
/>
<card-cvc
:stripe="stripeId"
:options="stripeOptions"
/>
推荐阅读
- javascript - 在 Jest 中模拟文件加载期间调用的函数
- javascript - 如何使用传递的构造函数参数创建单例类实例?
- python - 箱线图上方和下方的数字
- aws-lambda - java lambda不要在aws x射线上写
- python - 在python中的对象内展平对象
- google-apps-script - Google Scripts 中是否有使用 Google Sheets 和 Google Docs 创建富 HTML 文本电子邮件的功能?
- java - 什么是在类数据字段中声明 Scanner 变量时没有资源泄漏?
- azure - Azure AKS 应用程序网关入口和 Istio 入口网关
- python - 如何在 jupyter notebook 上的 pd.DataFrame 对象上显示新添加的属性
- r - R - 对 tidyverse 数据框的列进行类型检查时出现意外行为