0
votes

I'm trying to create a custom component in Vue.

This is the simplest component I could come up with and the value prop is ALWAYS undefined.

<template>
    <div>
        - {{ value }} -
    </div>
</template>

<script>
    export default {
        props: ['value'],

        mounted() {
            console.log(this.value);
        }
    }
</script>

Not doing anything special when I call it:

<el-text-group v-model="testVar"></el-text-group>

{{ testVar }}

The variable testVar shows fine, but the custom component shows nothing?

I've followed a bunch of tutorials and the official docs:

https://vuejs.org/v2/guide/components.html#Form-Input-Components-using-Custom-Events

I'm using latest Vue 2.4.2. It seems to work fine with Vue 2.2.x.

I've actually had this issue months ago but thought I would wait to see if something got fixed. But testing again now and the issue is still there. No idea, seems very basic, not sure if there is some change on how to do this?

FILES:

app.js

var component = require('./components/App.vue');

component.router = Vue.router;

new Vue(component).$mount('#app');

App.vue

<template>
    <div>
        Hello

        <hr/>

        <test-cpt v-model="testVar"></test-cpt>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                testVar: 'test'
            };
        },

        components: {
            testCpt: require('./TestCpt.vue')
        }
    }
</script>

TestCpt.vue

<template>
    <div>
        - {{ value }} -
    </div>
</template>

<script>
    export default {
        props: ['value']
    }
</script>
1
what do you expect value would be in the code you posted?Jaromanda X
It's not a Vue problem. codepen.io/Kradek/pen/zdemVW?editors=1010Bert
@JaromandaX testVar shows "test" just fine, but in the custom component (input) it's all empty and shows undefined in console.Rob
Show how you are using the component.Bert
Works fine with webpack as well. What I meant by show how it's used is show where you import it, register it, etc. Essentially the parent component.Bert

1 Answers

0
votes

Removing node_modules and reinstalling seemed to fix it.