Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

VueJS 3 : value cannot be made reactive: undefined

Hello,

I want to update my VueJS code from option API to composition API.

I have the code below.

<script setup>
  import { reactive } from 'vue';
  import apiAuth from '@/services/apiAuth.js';

  const user = reactive();

  async function login() {
    await this.$store.dispatch('auth/login', user);

    this.$router.push({ path: '/dashboard' });
  }
</script>

<template>
  <el-row align="middle" justify="center">
    <el-col :xs="22" :sm="12" :md="8">
      <el-card>
        <el-form
          label-width="100px"
          style="max-width: 460px"
        >
          <el-form-item label="Adresse mail">
            <el-input
            	v-model="user.email"
            	placeholder="Adresse mail">
            </el-input>
          </el-form-item>

          <el-form-item label="Mot de passe">
            <el-input
            	v-model="user.password"
            	type="password"
            	placeholder="Mot de passe">
            </el-input>
          </el-form-item>

          <el-button type="primary" @click="login()">Se connecter</el-button>
        </el-form>
      </el-card>
    </el-col>
  </el-row>
</template>

<style lang="scss" scoped>
  .el-row {
    display: flex;
    height: calc(100vh - 103px);
  }
</style>

It generates this error.

value cannot be made reactive: undefined

I really don't understand why.

Furthermore the setup attribute in the script tag seems to not be recognized. Perhaps it's the origin of the error ?

Do you have any idea ?

Thanks for your help.

Vincent

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

The error "value cannot be made reactive: undefined" is occurring because the user object is not initialized with any properties. In the code provided, user is declared as a reactive object using the reactive function from Vue 3, but it is not given any initial properties.

To fix this issue, you need to initialize the user object with the required properties (in this case, email and password). Here's an updated version of the code:

<script setup>
  import { reactive } from 'vue';
  import apiAuth from '@/services/apiAuth.js';

  const user = reactive({
    email: '',
    password: ''
  });

  async function login() {
    await this.$store.dispatch('auth/login', user);

    this.$router.push({ path: '/dashboard' });
  }
</script>

<template>
  <el-row align="middle" justify="center">
    <el-col :xs="22" :sm="12" :md="8">
      <el-card>
        <el-form
          label-width="100px"
          style="max-width: 460px"
        >
          <el-form-item label="Adresse mail">
            <el-input
              v-model="user.email"
              placeholder="Adresse mail"
            ></el-input>
          </el-form-item>

          <el-form-item label="Mot de passe">
            <el-input
              v-model="user.password"
              type="password"
              placeholder="Mot de passe"
            ></el-input>
          </el-form-item>

          <el-button type="primary" @click="login()">Se connecter</el-button>
        </el-form>
      </el-card>
    </el-col>
  </el-row>
</template>

<style lang="scss" scoped>
  .el-row {
    display: flex;
    height: calc(100vh - 103px);
  }
</style>

In this updated code, the user object is initialized with email and password properties set to empty strings. This ensures that the user object is reactive and can be used in the template without causing the "value cannot be made reactive: undefined" error.

1 like

Please or to participate in this conversation.