2

I'm trying to create a custom component with VueJS & Element-UI and I'm getting a very annoying error when trying to enter data into the input field.

Below are the files & the contents related to the issue:

components.js file:

Vue.component('yetti-input', {
    props: ['value'],
    template: '<el-input ref="input" v-bind:value="value" v-on:input="parseValue($event.target.value)"></el-input>',
    methods: {
        parseValue (value) {
            this.$emit('input', value)
        }
    }
})

index.vue file:

<template>
    <div>
        <div class="login-form">
            <yetti-form>
                <yetti-input v-model="login.email"></yetti-input>
            </yetti-form>
        </div>
    </div>
</template>

<script>
    export default {
        data () {
            return {
                login: {
                    email: '',
                    password: ''
                }
            }
        }
    }
</script>

Error I'm receiving in the Console: enter image description here

Please point out if I'm being a fool, however I cannot for the life of me figure out what is going on.

Cheers, Tim

1
  • So, it appears to be related to el-input. When using input, all good. However, calling the el-input and attempting this, it doesn't work. So perhaps a different question would be: How do I add data values to an el-input when it is in a component? Commented Feb 22, 2018 at 17:55

1 Answer 1

2

Okay, I solved my problem.

Interestingly, the $event is the input value being provided when using el-input.

Rather than have: v-on:input="parseValue($event.target.value)"

I removed target.value and I had my value. v-on:input="parseValue($event)"

Not sure if I've done the wrong thing by VueJS here. However, this has resolved my issue.

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

Comments

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.