0

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

Just found one solution, but maybe threre's a better one?

  1. Install this package https://packagist.org/packages/laracasts/utilities
  2. In server do
JavaScript::put(['langs' => [
   july => __('configname.july'),
   august => __('configname.august')
]])
  1. in client do this
Vue.use(AirbnbStyleDatepicker, {monthNames: [
       'January',
       'February',
       'March',
       'April',
       'May',
       'June',
       window.langs['july'],
       window.langs['august'],
       'September',
       'October',
       'November',
       'December',
   ],});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.