首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Laravel Spark的``update payment-method-stripe`组件中,`billlable`来自哪里?

在Laravel Spark的``update payment-method-stripe`组件中,`billlable`来自哪里?
EN

Stack Overflow用户
提问于 2017-07-29 02:12:32
回答 1查看 280关注 0票数 2

如果是Laravel Spark,则有一个具有以下内联模板的vue组件

代码语言:javascript
复制
<spark-update-payment-method-stripe :user="user" :team="team" :billable-type="billableType" inline-template>
    /* ... */
            <div class="pull-right">
                <span v-if="billable.card_last_four">
                    <i :class="['fa', 'fa-btn', cardIcon]"></i>
                    ************@{{ billable.card_last_four }}
                </span>
            </div>
    /* ... */
</spark-update-payment-method-stripe>

此模板包含变量billable.card_last_four

如果我查找该组件的定义文件,我会看到以下内容

代码语言:javascript
复制
#File: resources/assets/js/spark-components/settings/payment-method/update-payment-method-stripe.js
var base = require('settings/payment-method/update-payment-method-stripe');

Vue.component('spark-update-payment-method-stripe', {
    mixins: [base]
});

如果我追踪到基本组件,我会看到一个定义的vue组件

代码语言:javascript
复制
#File: spark/resources/assets/js/settings/payment-method/update-payment-method-stripe.js
module.exports = {
    props: ['user', 'team', 'billableType'],
/* ... */

但是,这些组件似乎都没有定义billable anywhere。我看到很多关于this.billable的引用。

代码语言:javascript
复制
#File: spark/resources/assets/js/settings/payment-method/update-payment-method-stripe.js
/* ... */

this.form.address = this.billable.billing_address;
this.form.address_line_2 = this.billable.billing_address_line_2;
this.form.city = this.billable.billing_city;
this.form.state = this.billable.billing_state;
this.form.zip = this.billable.billing_zip;
this.form.country = this.billable.billing_country || 'US';

/* ... */                
placeholder() {
    if (this.billable.card_last_four) {
        return `************${this.billable.card_last_four}`;
    }

    return '';
}
/* ... */

这个billable属性是从哪里来的?我假设Vue正在做某种形式的元编程和/或魔法来填充它,但我对Vue还不够熟悉,无法知道发生了什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-29 02:43:53

在上面的Bert Evansthanksd以及Chrome VueJS debugger的帮助下,我得到了我想要的答案

billable属性实际上是一个计算属性。但是,它不是在update-payment-method-stripe.js定义文件中本地计算的。相反,Spark有一个包含以下内容的vue-bootstrap.js

代码语言:javascript
复制
Vue.mixin(require('./mixin'));

事实证明VueJS有一个global mixin特性(看起来像?)为系统中的每个组件添加一个方法。mixin模块如下所示

代码语言:javascript
复制
#File: spark/resources/assets/js/mixin.js
module.exports = {
    computed: {
        /**
         * Get the billable entity.
         */
        billable() {
            /* ... */
        },
        /* ... */
    }
};

这意味着spark中的每个组件都将具有此计算机billable属性。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45379897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档