Detailed explanation of vue.js dynamic components

Detailed explanation of vue.js dynamic components

:is dynamic component

Use v-bind:is="component name" to automatically find a matching component name. If there is no matching component name, it will not be displayed.

<div id="app">
    <test v-bind:is="which_to_show"></test>
</div>

<script>
    var demo = new Vue({
        el: "#app",
        data: {
            which_to_show: "first"
        },
        components:
            first: {
                template: "<div>Here is the subcomponent first</div>"
            },
            second: {
                template: "<div>Here is the subcomponent second</div>"
            },
            third: {
                template: "<div>Here is the subcomponent third</div>"
            }
        }
    });
</script>

Write the picture description here

By changing the value of which_to_show, you can dynamically change the component you want to load and render, as follows:

Write the picture description here

This is the end of this article about the detailed explanation of vue.js dynamic components. For more relevant vue.js dynamic component content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue.js dynamic component analysis
  • Vue.js parent-child component communication dynamic binding example
  • Implementation of dynamic component templates in Vue.js
  • Detailed explanation of the usage of scoped slots in Vue.js slots
  • Front-end architecture vue architecture slot usage tutorial
  • Basic usage specifications of slots in Vue2
  • Vue default slot, named slot, scope slot definition and usage
  • Summary of the use of vue.js dynamic components and slots

<<:  Detailed explanation of MySQL foreign key constraints

>>:  Detailed tutorial on building a private Git server on Linux

Recommend

How to install docker on ubuntu20.04 LTS

Zero: Uninstall old version Older versions of Doc...

Issues and precautions about setting maxPostSize for Tomcat

1. Why set maxPostSize? The tomcat container has ...

Installation and use tutorial of Elasticsearch tool cerebro

Cerebro is an evolution of the Elasticsearch Kopf...

Take you to understand the event scheduler EVENT in MySQL

The event scheduler in MySQL, EVENT, is also call...

Nginx server adds Systemd custom service process analysis

1. Take nginx as an example Nginx installed using...

Example explanation of alarm function in Linux

Introduction to Linux alarm function Above code: ...

CSS3 realizes various graphic effects of small arrows

It’s great to use CSS to realize various graphics...

Flash embedded in web pages and IE, FF, Maxthon compatibility issues

After going through a lot of hardships, I searched...

JS ES new features template string

Table of contents 1. What is a template string? 2...

HTML n ways to achieve alternate color code sample code

This article mainly introduces the sample code of...

The simplest form implementation of Flexbox layout

Flexible layout (Flexbox) is becoming increasingl...

Vue implements the browser-side code scanning function

background Not long ago, I made a function about ...

Vue must learn knowledge points: the use of forEach()

Preface In front-end development, we often encoun...

Complete steps of centos cloning linux virtual machine sharing

Preface When a Linux is fully set up, you can use...

Solve the error "Can't locate ExtUtils/MakeMaker.pm in @INC"

When installing mha4mysql, the steps are roughly:...