<script>
import axios from 'axios'
export default {
data () {
return {
center: {lat: 45.101637, lng: 38.986345},
markers: []
}
},mounted()
{
let vm = this
vm.getMarkers();
},
methods: {
getMarkers() {
let vm = this
axios.get('/api/markers')
.then(function(response) {
vm.markers = response.data.data
})
vm.markers = response.data.data.map(m => {
return {
name: m.name,
address: m.address,
position: { lat: m.lat, lng: m.lng }
}
})
},
}
}
</script>
Error in mounted hook: "ReferenceError: response is not defined"
<div class="col-md-8">
{{ marker.name }}</br>
{{ marker.address }}</br>
{{ marker.lat }}</br>
{{ marker.lng }}</br>
</div>
namespace App;
use Illuminate\Database\Eloquent\Model;
class Marker extends Model
{
protected $fillable = [
'id', 'name', 'address', 'lat', 'lng', 'type',
];
}
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class Marker extends JsonResource
{
public function toArray($request)
{
return parent::toArray($request);
return [
'id' => $this->id,
'name' => $this->name,
'address' => $this-> address,
'lat' => $this-> lat,
'lng' => $this-> lng,
'type' => $this-> type,
];
}
}