0

The desired behaviour:

/component.vue

export default {
  data(){
    return{
      rowData: []
    }
  } 
}

I would like to define the data from a vue component in a external file.

error: rowData is not defined.

/component.vue

import datas from './options.js'

export default {
  data(){
    return{
      datas
    }
  } 
}

/options.js


export default datas = {
  rowData: []
};

2 Answers 2

2

You should try this:

import datas from './options.js'

export default {
  data(){
    return{
      ...datas
    }
  } 
}

or:

import datas from './options.js'

export default {
  data(){
    return datas
  } 
}

if no more data is added.

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

Comments

1

You're missing the const keyword in your options.js , try to add it like :

  const datas = {
  rowData: []
 };
 export default datas;

and in your compponent.vue :

   import datas from './options.js'

  export default {
      data(){
         return{
               datas:datas
             }
           } 
         }

3 Comments

Actually export default const doesn't seems to be valid - developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
yeah but the OP is naming that object so she should add let or const
but this is not valid syntax: stackoverflow.com/questions/36261225/…

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.