How to use Slots to Populate Content with Vue 3

How to use Slots to Populate Content with Vue 3

A way to distribute content in a component. Vue 3 is the up and coming version of Vue front end framework. It builds on the popularity and ease of use of Vue 2.

Vue 3 is in beta and it’s subject to change.

Vue 3 is the up and coming version of Vue front end framework.

It builds on the popularity and ease of use of Vue 2.

In this article, we’ll look at how to use slots to populate content with Vue 3.

Slots

We can add slots to let us distribute content to the location we want.

For instance, we can write:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>App</title>
    <script src="https://unpkg.com/[email protected]"></script>
  </head>
  <body>
    <div id="app">
      <click-button>click me</click-button>
    </div>
    <script>
      const app = Vue.createApp({});
      app.component("click-button", {
        template: `
          <button>
            <slot></slot>
          </button>`
      });
      app.mount("#app");
    </script>
  </body>
</html>

We created the click-button component with a slot inside so that we can add our own content between the tags.

javascript programming vuejs vue

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

8 Popular Websites That Use The Vue.JS Framework

In this article, we are going to list out the most popular websites using Vue JS as their frontend framework. Vue JS is one of those elite progressive JavaScript frameworks that has huge demand in the web development industry. Many popular websites are developed using Vue in their frontend development because of its imperative features.

Vue.js Tab Components Based on Vue Router

vue-router-tab .A tab router component based on Vue Router.

5 JavaScript tips learned from Vue source code

5 JavaScript Tips I Learned From Vue Source Code - Learn JavaScript from the source code of the popular JS frameworks.

Vue Query Builder with Cube.js - A Tutorial

quite commonly in our applications, we need to create interactive report builders to let users build custom reports and dashboards. This usually involves selecting the metrics, groupings, date ranges, filters, and chart types. To help developers build such interactive components, we've created a query builder component in Cube.js client libraries.

VueJs Form Validation Part 2 — Vuelidate

In my last article, I covered the VueJs validation package VeeValidate. In part 2, we’re going to be talking about another popular validation package called Vuelidate. While VeeValidate took a template-based approach, Vuelidate is the exact opposite with a model-based approach. Just like the last article, we’ll be looking at how we can use this package on a signup form. This will give you a clear idea of how you can use this on just about any form.