I'm passing user data to a component via Laravel, this data contains a distance in miles, however the user has the option to set the view distance in km, so I have to pass profile.distance_mi to be computed, how do I accomplish this?
HTML:
<saved profiles="{{json_encode($profiles)}}" unit="{{Auth::user()->settings->unit}}"></saved>
<div v-for="profile in profiles" class="col-xs-12 col-sm-4 col-md-3">
...
<h4>@{{distance}}</h4>
....
</div>
JS
new Vue(
{
el: 'body',
components:
{
saved:
{
template: '#saved',
props: ['profiles', 'unit'],
created: function ()
{
this.profiles = JSON.parse(this.profiles);
},
computed:
{
distance: function ()
{
var unit = this.unit;
return unit == 0 ? Math.round(distance * 1.60934) + ' km' : distance + ' miles';
}
}
}
}
});