how do you guys pass data from php to vue in non-spa set up ?
how i do (it is working):
controller:
Route::get('server-to-vue',function(){
//use laracasts/utilities package
\JavaScript::put([
'test'=>request()->input('test'),
'countries' =>\App\Utilities\Countries::all(),
]);
return view('blade');
});
component.vue
<template>
<div>
<select>
<option v-for="(country,country_code) in countries" v-bind:value="country_code">
{{ country }}
</option>
</select>
<hr>
$_GET['test'] : {{test}}
</div>
</template>
<script>
import common_mixin from './CommonMixin'
export default {
mixins : [common_mixin],
server_variables : ['test','countries'],
data() {
return {
test:'',
countries : [],
}
},
mounted() {
this.loadDataFromGobals();
},
methods: {
}
}
</script>
CommonMixin.js
export default {
methods: {
loadDataFromGobals: function() {
let variables = this.$options.server_variables
if(variables == undefined)
return ;
let self = this;
variables.map(variable => {
self[variable] = window[variable];
});
}
}
}
any suggestion to this implementation?
any better implementation?