<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>
<alien-component :value="value" @input="$emit('input', this.$event.target.value)" />
<alien-component
:value="value"
@input="$emit('input', $event)"
/>