【问题标题】:Laravel pass accessor to vueLaravel 将访问器传递给 vue
【发布时间】:2017-07-13 08:49:44
【问题描述】:

在我的一个 Laravel 5.4 模型上,我有多个访问器。像这样:

public function getRevenueAttribute()
{
    return $this->calculate()->revenue($this->price, $this->amount);
}

问题是当我将模型传递给我的 vue 组件时:

<product :prp-product="{{json_encode($product)}}"></product>

product.revenue 不存在。有没有办法做到这一点?我不想再在vue中计算这些东西了。

非常感谢。

【问题讨论】:

    标签: php laravel vue.js


    【解决方案1】:

    您需要为模型添加appends 属性,请参阅this 了解更多信息。

    /**
     * The accessors to append to the model's array form.
     *
     * @var array
     */
    protected $appends = ['revenue'];
    

    【讨论】:

      猜你喜欢
      • 2018-12-03
      • 2020-07-30
      • 2021-07-19
      • 1970-01-01
      • 2018-06-20
      • 2018-10-23
      • 2019-10-07
      • 2020-02-11
      • 1970-01-01
      相关资源
      最近更新 更多