1

I'm trying to import an array into a Vue component:

The (simplified) component:

<script type="text/babel">
    const countryCodes = require('./country_codes.js');

    export default {
        props: [],

        data() {
            return {
                countryCodes: countryCodes
            }
        },
    }
</script>

country_codes.js

(function() {
   return ['DE', 'EN']; // This, of course, is way bigger; simplified for readability
});

Both the component and the country_codes.js files are in the same directory, but the countryCodes property is always an empty object.

What am I doing wrong?

1 Answer 1

4

I can't tell for what reason your code isn't working. Maybe you just need to export your data from countryCodes.js

So, I am sure this will work

import countryCodes from './countryCodes.js'

countryCodes.js

export const countryCodes = {
  return ['DE', 'EN'];
}
3
  • Thank you. That put me on the right track. Plus cour code works just fine.
    – lesssugar
    Commented Mar 5, 2018 at 14:01
  • Strange. For me it shoots an error: Unexpected keyword 'return' (2:4) Any hints on that?
    – Dong3000
    Commented Aug 19, 2020 at 8:13
  • Maybe you don't have es6 support
    – samayo
    Commented Aug 19, 2020 at 18:50

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.