mo3n
mo3n

Reputation: 1870

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

I have a Vue.js component (named <dynamic-input/>) which accepts a prop (called input). I'm trying to pass the returning value of a method (named normalizeInput) which is defined in the 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

Upvotes: 1

Views: 2739

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

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

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

Upvotes: 3

Related Questions