0

I have the following code where I am creating a simple login form everything works file until i try to type into the form input, it seems I cannot type into the form fields. The following is my code. I have to mention that I am not calling any server api yet.

<template>
    <el-row justify="center">
        <el-col :span="6" class="login">
            <el-card shadow="always">
                <template #header>
                    <span>Memeber Login</span>
                </template>
                <div class="login__inner">
                    <el-form ref="user" :model="user">
                        <el-form-item>
                            <el-input
                                v-model="user.email"
                                placeholder="Email Address"
                                clearable
                                prefix-icon="message">
                            </el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-input
                                v-model="user.password"
                                placeholder="Password"
                                clearable show-password
                                prefix-icon="lock"
                            >
                            </el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary">
                                <el-icon><check /></el-icon> Login
                            </el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </el-card>
        </el-col>
    </el-row>
</template>

<script lang="js">
import { reactive } from 'vue';

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

        return {
            user,
        };
    },
};
</script>

Edit: here is the image.

Image Link

4
  • If you are using vue3, where do the el-x components come from? Commented Nov 30, 2021 at 8:16
  • I am also using element-plus ui library that where the el-* components come from Commented Nov 30, 2021 at 8:31
  • I can't see the component imports in your code Commented Nov 30, 2021 at 8:41
  • they have been imported in main.js.. the components work fine when i use the old options api it works but when i change it to comp-api that's when this problem occurs ... I just added the image that shows the components working Commented Nov 30, 2021 at 8:49

2 Answers 2

1

The attribute ref="user" on el-form conflict with reactive user key, just use other word like ref="userForm" See here

Sign up to request clarification or add additional context in comments.

Comments

0

Try the following alternative for the <script> section:

<script lang="js">
export default {
  name: "LoginForm",
  data() {
    return {
      user: {
          email: '',
          password: ''
        }
    }
};
</script>

where LoginForm is your component name.

1 Comment

What you have done is the option API I was trying to do it using Composition API, Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.