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'];
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. That put me on the right track. Plus cour code works just fine.
Strange. For me it shoots an error: Unexpected keyword 'return' (2:4) Any hints on that?
Maybe you don't have es6 support

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.