'Is it possible to import vue-datepicker language via a variable

I am using vue-datepicker plugin in my project. According to the docs, you set the language like this:

<datepicker :language="nl" />

And

import {nl} from 'vuejs-datepicker/dist/locale'

And

 data() {
   return {
     nl: nl
   }
 }

My question is: Is it possible to use a variable coming from a parent component or an env file to load all of this ?

So something like this:

CountryCode = "nl" //Coming from somewhere

<datepicker :language=CountryCode />
import {CountryCode} from 'vuejs-datepicker/dist/locale'
data() {
  return {
    CountryCode: CountryCode
  }
}

I know the code above is totally incorrect, but just trying to show what i mean, if that makes any sense.



Solution 1:[1]

If I'm not mistaken, the only types allowed for a prop are:

  • String
  • Number
  • Boolean
  • Array
  • Object
  • Date
  • Symbol
  • Function

Even passing a Function is usually seen as an anti-pattern, unlike in React.

So, I doubt that this is possible and even if it could, it would be quite strange. So I don't recommend it anyway.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kissu