Answer the question
In order to leave comments, you need to log in
How to properly pass props to a component?
Hello, I myself develop on React, but I have to support projects on Vue. I can't quite figure out how to properly pass props to a component. There is an Input component :
<template>
<input class="Input" v-bind="restProps" v-on="$listeners">
</template>
<script>
export default {
props: ['placeholder', 'keyupEnter'],
computed: {
restProps: function() {
return {
placeholder: this.placeholder
}
}
}
}
</script>
<style lang="scss" scoped>
.Input {
width: 100%;
height: 42px;
padding: 0 17px;
font-size: 12px;
border: 1px solid #E3E3E3;
border-radius: 2px;
}
</style>
<Input placeholder="Название вопроса"
:value="question.name"
@input="actions.changeQuestionName(index, $event)" />
<Input placeholder="Название ответа"
@keyup.enter="actions.addQuestionAnswer.bind(null, index)" />
Answer the question
In order to leave comments, you need to log in
If I understand correctly, there are inheritAttrs and $attrs options .
And you can pass all properties
By default, undeclared props are hung on the root element of the component.
inheritAttrs can override this in order to put them on another element. for example
<div class="inputbox">
<input v-bind="$attrs">
</div>
{
inheritAttrs: false
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question