У меня есть следующее в App.vue
<template>
<div id="app">
<input type="text" v-model="term">
<hello-world text="Button 1" v-if="term === ''"></hello-world>
<hello-world v-else text="Button 2"></hello-world>
</div>
</template>
<script>
import HelloWorld from '@/components/HelloWorld'
export default {
name: 'app',
data() {
return {
term: ''
}
},
components: {
HelloWorld
}
}
</script>
А вот HelloWorld.vue
:
<template>
<div>
<button>{{ text }}</button>
</div>
</template>
<script>
export default {
props: {
text: String
},
created() {
console.log('Created')
},
destroyed() {
console.log('Destroyed')
}
}
</script>
Итак, когда я что-то печатаю, первый компонент должен быть уничтожен иВторой компонент должен быть создан.Однако ничего подобного не происходит.Компонент не уничтожается и не создается.
Как будто v-if
не вызвал функцию created()
& destroyed()
.Пожалуйста, помогите мне с этим.