Vue Js Slot Component Example Tutorial

Vue.Js

Nicesnippets

166

18-08-2020


Hii Guys

In this example, I will explain you how to use slot in vue.js, we will show basic example of vue js slot.Vue implements a content distribution API inspired by the Web Components spec draft, using the <slot> element to serve as distribution outlets for content.

Here, I will give you full example for simply display Slot Component invue js example as bellow.

Script Code


<script>

Vue.config.devtools = true

var app = new Vue({

el:'btn-slot',

data:{

show: true,

},

template: `<p>

<slot></slot>

</p>`

})

</script>

Full Example

<!DOCTYPE html>

<html>

<head>

<title>Vue Js Slot Example</title>

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.0-alpha1/css/bootstrap.min.css">

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

</head>

<body class="bg-dark">

<div class="container">

<div class="col-md-6 offset-md-3">

<div class="card mt-5">

<div class="card-header">

<h5>Vue Js Slot Example</h5>

</div>

<div class="card-body">

<div class="row">

<div class="col-md-12">

<btn-slot>

Hello Dev

</btn-slot>

</div>

</div>

</div>

</div>

</div>

</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/vue.min.js"></script>

<script>

Vue.config.devtools = true

var app = new Vue({

el:'btn-slot',

data:{

show: true,

},

template: `<p>

<slot></slot>

</p>`

})

</script>

</body>

</html>

It Will help you...


Recommended Posts