Stripe() 的值无效:apiKey 应为字符串。您指定:未定义

Fio*_*lar 12 javascript vue.js vuejs2

我正在使用“Vue Stripe Checkout 3”组件,当我尝试实现它时,出现以下错误“

Invalid value for Stripe (): apiKey should be a string. You specified: undefined.
Run Code Online (Sandbox Code Playgroud)

在我的数据中我有:

publishableKey: process.env.PUBLISHABLE_KEY,
Run Code Online (Sandbox Code Playgroud)

我还尝试直接添加我的密钥(publishableKey:'我的密钥'),但它仍然不起作用。我也尝试过直接把它放在道具上,但什么也没有。

<template>
<div>
          <stripe-checkout 
          ref="checkoutRef" 
          :pk="publishableKey"
          :items="items"
          :successUrl="successUrl"
          :cancelUrl="cancelUrl">

    <template slot="checkout-button">
      <button @click="checkout" class="btn-yellow wow fadeInUp btn" style="visibility: visible; animation-name: fadeInUp;">Pagar</button>
    </template>
  </stripe-checkout>
       
</div>
</template>

<script>
import { StripeCheckout } from 'vue-stripe-checkout';

export default {
   components: {
    StripeCheckout
  },
   data: () => ({
    loading: false,
publishableKey: 'sk_test_51H85e2F5x69G5dDPxFEtO0RyIBWBEWkqwV9fpN5ovLysfCxJ15kfyeALoUFdZNi57yt0zj40h4LV3l5Zkra6WPCw00by0N0W3a',
    items: [
      {
        sku: item.sku, 
        quantity: 1
      }
    ],
    successUrl: 'https://tarfut.es',
    cancelUrl: 'https://tarfut.es',
  }),
    
    methods: {
      checkout () {
      this.$refs.checkoutRef.redirectToCheckout();
    },
    },
}
</script>
Run Code Online (Sandbox Code Playgroud)

提前致谢。

cho*_*nz0 32

我在 Next.js 应用程序中遇到了类似的错误,我通过将密钥类型转换为string.

尝试更换:

publishableKey: process.env.PUBLISHABLE_KEY,
Run Code Online (Sandbox Code Playgroud)

和:

publishableKey: `${process.env.PUBLISHABLE_KEY}`,
Run Code Online (Sandbox Code Playgroud)