How to Fix 'Property Not Defined on Instance' Error in Vue
property not defined on instance error in Vue happens when you try to use a property that Vue does not know about in its reactive system. To fix it, declare the property inside the data() function or define it properly in setup() when using Composition API.Why This Happens
This error occurs because Vue's reactivity system only tracks properties that are declared in the component's data() or returned from setup(). If you try to access or bind a property that is not declared, Vue cannot find it on the component instance and throws this error.
<template>
<div>{{ message }}</div>
</template>
<script>
export default {
data() {
return {
// 'message' is missing here
};
}
}
</script>The Fix
To fix this, declare the property inside the data() function so Vue can track it reactively. If using Composition API, define and return it from setup(). This makes the property available on the component instance and removes the error.
<template>
<div>{{ message }}</div>
</template>
<script>
export default {
data() {
return {
message: 'Hello Vue!'
};
}
}
</script>Prevention
Always declare all reactive properties you plan to use in your template or methods inside data() or setup(). Use Vue's devtools or linting tools to catch undeclared properties early. This helps avoid runtime errors and keeps your code clear.
Related Errors
Similar errors include:
- "Method not defined on instance": Fix by declaring methods inside the
methodsoption. - "Computed property not defined": Fix by defining computed properties inside the
computedoption.