Fix: Property Already Defined in Vue.js

Error message:
{type} property "{key}" is already defined in {source}.
Props & Properties 2025-01-25

What Causes This Warning?

This warning occurs when you define a property with the same name in multiple places within a component, such as in props, data, computed, or methods. Each property name must be unique.

The Problem

export default {
  props: ['name'],
  data() {
    return {
      name: 'John' // ❌ Already defined in props!
    }
  }
}

The Fix

Use Unique Names

export default {
  props: ['name'],
  data() {
    return {
      localName: 'John' // ✅ Different name
    }
  }
}

Common Conflicts

Props vs Data

// ❌ Conflict
export default {
  props: ['count'],
  data() {
    return {
      count: 0
    }
  }
}

// ✅ Fixed
export default {
  props: ['initialCount'],
  data() {
    return {
      count: this.initialCount
    }
  }
}

Props vs Computed

// ❌ Conflict
export default {
  props: ['items'],
  computed: {
    items() { // Same name as prop!
      return this.rawItems.filter(x => x.active)
    }
  }
}

// ✅ Fixed
export default {
  props: ['items'],
  computed: {
    filteredItems() {
      return this.items.filter(x => x.active)
    }
  }
}

Props vs Methods

// ❌ Conflict
export default {
  props: ['submit'],
  methods: {
    submit() { // Same name as prop!
      // ...
    }
  }
}

// ✅ Fixed
export default {
  props: ['onSubmit'],
  methods: {
    handleSubmit() {
      this.onSubmit?.()
    }
  }
}

Data vs Computed

// ❌ Conflict
export default {
  data() {
    return {
      fullName: ''
    }
  },
  computed: {
    fullName() { // Same name as data!
      return `${this.firstName} ${this.lastName}`
    }
  }
}

// ✅ Fixed
export default {
  data() {
    return {
      firstName: '',
      lastName: ''
    }
  },
  computed: {
    fullName() {
      return `${this.firstName} ${this.lastName}`
    }
  }
}

Composition API

<script setup>
import { ref, computed } from 'vue'

const props = defineProps(['value'])

// ❌ Conflicts with prop
// const value = ref(0)

// ✅ Use different name
const localValue = ref(props.value)

// Or use computed for derived values
const doubledValue = computed(() => props.value * 2)
</script>

Naming Conventions

// ✅ Good naming patterns
export default {
  props: {
    initialValue: Number,  // "initial" prefix for editable props
    userData: Object,      // Descriptive compound names
    onSubmit: Function     // "on" prefix for event handlers
  },
  data() {
    return {
      value: this.initialValue,  // Local version of prop
      user: null,                // Shorter local name
      isLoading: false
    }
  },
  computed: {
    processedUser() {  // "processed" for derived data
      return transform(this.user)
    }
  },
  methods: {
    handleSubmit() {  // "handle" prefix for methods
      this.onSubmit?.(this.user)
    }
  }
}

Quick Checklist

  • Each property name must be unique across props, data, computed, methods
  • Use prefixes: initial, local, on, handle
  • Rename conflicting properties to be more specific
  • Props typically represent external data; data is internal state
  • Computed derives from existing properties (shouldn’t shadow them)