VueJs
What is slot ?
Slot is vue element to display any contents from component registered. let see example below for more detail:
I have two files WaysBinding.vue and Slot.vue:
WaysBinding.vue content :
Importing slot component into WaysBinding component: import navigationLink from './Slot.vue'
Registering components : components:{ navigationLink }
The contents Logged in as Pika leak will replace <slot></slot>
Slot.vue content :
the final result displays to browser :
Logged in as Pika leak will replace Your Profile
Slot is vue element to display any contents from component registered. let see example below for more detail:
I have two files WaysBinding.vue and Slot.vue:
WaysBinding.vue content :
<template>
<div>
<p>{{ message }}</p>
<input v-model="message">
<navigation-link url="/profile">
<!-- Add a Font Awesome icon -->
<span class="fa fa-user"></span>
Logged in as {{ user.name }}
</navigation-link>
</div>
</template>
<script>
import navigationLink from './Slot.vue'
export default {
components:{
navigationLink
},
name:'WaysBinding',
data(){
return {
message:'hellow word',
user:{
name:'Pika leak'
}
}
}
}
</script>
Importing slot component into WaysBinding component: import navigationLink from './Slot.vue'
Registering components : components:{ navigationLink }
The contents Logged in as Pika leak will replace <slot></slot>
Slot.vue content :
<template>
<a
v-bind:href="url"
class="nav-link"
>
<slot></slot> {{ profile}}
</a>
</template>
<script>
export default {
name:'navigation-link',
props:['url'],
data() {
return {
profile: 'Your Profile'
}
}
}
</script>
the final result displays to browser :
Logged in as Pika leak will replace Your Profile
Comments
Post a Comment