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: []
};
Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164
sarnei
  • 267
  • 1
  • 4
  • 11

2 Answers2

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.

Beniamin H
  • 2,048
  • 1
  • 11
  • 17
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
             }
           } 
         }
Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164