Answer the question
In order to leave comments, you need to log in
How to properly wrap foreign components?
Good afternoon.
I found someone else's cool input, I want to correct it and use it with my settings. How to "wrap" it correctly so as not to change the component itself? In other words, I want to bring v-model to AlienComponent while maintaining reactivity.
I'm trying to implement something like this:
<template>
<div>
<input
type="text"
:value="value"
@input="$emit('input', $event.target.value)"
>
</div>
</template>
<script>
export default {
name: 'alien-component',
props: { value: [String] }
};
</script>
<template>
<div>
<label>{{ label }}</label>
<alien-component
:value="value"
@input="$emit('input', this.$event.target.value)"
/>
<!--
@input="$emit('input', this.$event.target.value)"
вызывает ошибку: Avoid mutating a prop directly since the value will be overwritten
-->
</div>
</template>
<script>
import AlienComponent from './AlienComponent.vue';
export default {
name: 'my-cool-input',
components: { AlienComponent },
props: { value: [String], label: [String] }
};
</script>
<template>
<div>
<h1>TEST</h1>
<my-cool-input label="ввод:" v-model="my_value"/>
</div>
</template>
<script>
export default {
data() {
return {
my_value: 'test value'
};
}
};
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question