Last active
July 13, 2019 23:08
-
-
Save matticustard/248371ef6c2380ddb08d61a86741f183 to your computer and use it in GitHub Desktop.
Laravel Vue Sample for StackOverflow user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you should have imports for | |
// Vue, axios, bootstrap, and anything else first | |
// ... | |
// ... | |
// check the directory to make sure yours matches this or update accordingly | |
Vue.component('app', require('./components/App.vue').default); | |
// define your root Vue element | |
const root = new Vue({ | |
el: '#root', | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<!-- Display results --> | |
<h1 v-for="(result, index) in results"> | |
Result {{ result.id }} name: {{ result.name }} | |
</h1> | |
<!-- End Display results --> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: "App", | |
data() { | |
return { | |
results: [], | |
} | |
}, | |
mounted() { | |
axios.get('/data') | |
.then(response => { | |
console.log(response); | |
this.results = response.data; | |
}) | |
.catch(errors => { | |
console.log(errors); | |
}); | |
} | |
} | |
</script> | |
<style scoped> | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('layouts.app') | |
@section('content') | |
<!-- Vue root --> | |
<div id="root"> | |
<!-- Vue component --> | |
<app></app> | |
<!-- End Vue component --> | |
</div> | |
<!-- End Vue root --> | |
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// you would want to use controllers | |
// for your logic once you get things working | |
// your HTML application | |
Route::get('/',function() { | |
return view('index'); | |
}); | |
// your request for a JSON response | |
Route::get('/data',function() { | |
return response()->json([ | |
[ | |
'id' => 1, | |
'name' => 'Laravel', | |
], | |
[ | |
'id' => 2, | |
'name' => 'Vue.js', | |
], | |
], 200); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment