data

{ data : {} | function(){} }

The data option allows you to set initial data values for your component in order to easily instantiate it in a specific state or scenario.

The data object can either be a plain object, or a function that returns an object. The returned object is merged with the original data object.

const component = {
  data(){
    return {
      foo : 'foo',
      bah : 'bah'
    };
  }
};
const vm = mount(component, {
  data : {
    foo : 'changed'
  }
});

vm.foo === 'changed';
vm.bah === 'bah';

or

const vm = mount(component, {
  data(){
    return {
      foo : 'changed'
    };
  }
});

vm.foo === 'changed';
vm.bah === 'bah';

The data function's this context will be the component instance. It will also be passed the existing data object as its first parameter:

mount(component, {
  data(data){
    return {
      foo : data.foo + ' changed'
    };
  }
});

vm.foo === 'foo changed';
vm.bah === 'bah';

results matching ""

    No results matching ""