# На свойство-объект

Логика такая же, как и с примитивным свойством.

# Класс






 











class ObjectGetter {
  person = {
    firstName: 'Jane',
    lastName: 'Dow',
    get fullName() {
      return `${this.firstName} ${this.lastName}`
    }
  }

  changeFirstName() {
    this.person.firstName = 'Marcelinka';
  }
}

const instance = new ObjectGetter();

export default instance;

# Компонент





 

















<template>
  <div class="component-block">
    <span class="name">ObjectGetterOne</span>

    <div><b>fullName:</b> {{ person.fullName }}</div>
    <button @click="changeFirstName">Изменить имя</button>
  </div>
</template>

<script>
import ObjectGetter from '@example-services/ObjectGetter';

export default {
  data() {
    return {
      person: ObjectGetter.person,
      changeFirstName: ObjectGetter.changeFirstName.bind(ObjectGetter),
    };
  },
};
</script>

# Результат

ObjectGetterOne
fullName: Jane Dow
ObjectGetterTwo
fullName: Jane Dow
Обновлено: 12/12/2022, 3:53:53 PM