Reputation: 379
the plugin I want to use let's define variables in plugin declaration within app.js
Vue.use(AirbnbStyleDatepicker, {monthNames: [
'January',
'February',
'March',
'April',
'May',
'June',
'Julyyy',
'Augusttt',
'September',
'October',
'November',
'December',
],});
however my website has few locales which is managed in server, I usually encode vars from laravel and pass them as props. In this case this does not work. I didn't find how to initialize plugin with options in component, so what is the way to solve this?
Upvotes: 0
Views: 371
Reputation: 214
you can define that javascript array before you load "app.js" in the the view. And then just put it in app.js as const.
in view before app.js is inserted:
<script type="text/javascript">
const trans_month = {{getTransMonths()}}
</script>
then in you app.js
Vue.use(AirbnbStyleDatepicker, {monthNames: trans_month,});
or you could use ajax call to server, which will return array of translated months
Upvotes: 1
Reputation: 379
Just found one solution, but maybe threre's a better one?
JavaScript::put(['langs' => [
july => __('configname.july'),
august => __('configname.august')
]])
Vue.use(AirbnbStyleDatepicker, {monthNames: [
'January',
'February',
'March',
'April',
'May',
'June',
window.langs['july'],
window.langs['august'],
'September',
'October',
'November',
'December',
],});
Upvotes: 0