Home > Software engineering >  Is there a way to pass the returning value of a method as a prop to a Vue component?
Is there a way to pass the returning value of a method as a prop to a Vue component?

Time:12-27

I have a Vue.js component (named ) which accepts a prop (named 'input'); I'm trying to pass the returning value of a method (named 'normalizeInput') which is defined in parent component:

template:

<div v-for="input in inputList" :key="input.id">
    <dynamic-input :input="normalizeInput(input)" />
</div>

script:

methods: {
    normalizeInput(input) {
        //do something with input
        return normalizedInput;
    }
}

Apparently this doesn't work; Is there a way to achieve this? Am I Doing Something Wrong?

I'm Using nuxt v2.15.7

CodePudding user response:

You've to use a computed property that returns a function with the input as parameters :

computed: {
    normalizeInput() {
        
        return (input) =>{
            return normalizedInput;
           } 
    }
}
  • Related