在我的一个 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里计算这些东西了。
非常感谢。
最佳答案
您需要向您的模型添加一个appends
属性,请参阅this了解更多信息。
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['revenue'];
关于php - Laravel 将访问器传递给 vue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45075764/