Vue:Stripe 未定义 - 是否需要在任何地方都包含 Stripe? [英] Vue: Stripe is not defined - does stripe need to be included everywhere?

查看:105
本文介绍了Vue:Stripe 未定义 - 是否需要在任何地方都包含 Stripe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试仅在我需要的模板中包含条带依赖项时(在 Laravel Blade 中):

When I tried to include the stripe dependency only for the template where I need it (in laravel blade):

@push ('head_scripts')
    <script src="https://js.stripe.com/v3/"></script>
@endpush

...我收到错误ReferenceError: Stripe is not defined".所以我把它包含在我的主要头部"部分中,所以它无处不在.然后我在进入管理部分时遇到了同样的错误,因为它没有包含在该模板中.

..I got the error 'ReferenceError: Stripe is not defined'. So I included it in my main "head" partial, so it was included everywhere. Then I ran into the same error when going into the admin section, because it's not included in that template.

但它真的需要无处不在吗?

But does it really need to be included everywhere?

它只用在这样一个 vue 组件中:

It is only used in one vue component like this:

<script>
    let stripe = Stripe(`pk_test_zzzzzzzzzzzzzzz`);
    let elements = stripe.elements();
    let card = undefined;

即使没有渲染这个组件,它似乎也会被评估.我能以某种方式解决这个问题吗?

This component seems to be evaluated even when it isn't rendered. Can I get around this issue in some way?

推荐答案

我在不使用 Laravel 的 Vue 应用中遇到了这个问题.

I was having this problem in a Vue app not using Laravel.

但是为了修复它,我将脚本 <script src="https://js.stripe.com/v3/"></script> 放在我的 中>index.html

But to fix it i put the script <script src="https://js.stripe.com/v3/"></script> in my index.html

然后在组件中引用 Stripe 时,我使用了 window.Stripe 指向脚本并修复了 ReferenceError: Stripe is not defined 错误.

Then when referencing Stripe in a component i used window.Stripe That pointed to the script and fixed the ReferenceError: Stripe is not defined error.

这篇关于Vue:Stripe 未定义 - 是否需要在任何地方都包含 Stripe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆