58
loading...
This website collects cookies to deliver better user experience
v-show
will only use the display
property CSS to the element ! 🎨<template>
<div>
<button @click="changeState">
Switch state
</button>
<child v-show="isShowed" name="v-show" />
<child v-if="isLiving" name="v-if" />
</div>
</template>
<script>
import Vue from "vue"
import Child from "../child"
export default Vue.extend({
components: {
Child,
},
data() {
return {
isShowed: false,
isLiving: true,
}
},
methods: {
changeState() {
this.isShowed = !this.isShowed
this.isLiving = !this.isLiving
},
}
})
</script>
<template>
<div>
Hello from {{ name }}
</div>
</template>
<script>
import Vue from "vue"
export default Vue.extend({
props: {
name: String,
},
created() {
console.log(`Element named ${ this.name } is created`)
},
destroyed() {
console.log(`Element named ${ this.name } is destroyed`)
},
})
</script>
Element named v-show is created
Element named v-if is created
Element named v-if is destroyed
Element named v-if is created
Element named v-if is destroyed
Element named v-if is created
v-if
component is reload and have a new cyclehook !display property
for v-show component
when component is hiding<div style="display: none;">
Hello from v-show
</div>
Can be use with v-else-if
and v-else
Init load component is cheap
Toggle element is expensive
Element will have display: none
when set to false
Init load component is expensive
Toggle element is very cheap
Underrated skills in javascript, make the difference
for FREE if you follow me on Twitter and MP me 😁