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

Example of adding music video to HTML page

1. Video tag Supports automatic playback in Firef...

A brief discussion on the implementation principle of Vue slot

Table of contents 1. Sample code 2. See the essen...

Semanticization of HTML tags (including H5)

introduce HTML provides the contextual structure ...

Implementation of Docker deployment of SQL Server 2019 Always On cluster

Table of contents Docker deployment Always on clu...

Detailed explanation of Vue router routing

Table of contents 1. Basic use 2. Several points ...

Typescript+react to achieve simple drag and drop effects on mobile and PC

This article shares the specific code of typescri...

MySQL data table partitioning strategy and advantages and disadvantages analysis

Table of contents Why do we need partitions? Part...

Summary of several MySQL installation methods and configuration issues

1. MySQL rpm package installation # Download the ...

How to install and connect Navicat in MySQL 8.0.20 and what to pay attention to

Things to note 1. First, you need to create a my....

JavaScript+html to implement front-end page sliding verification

This article shares the specific code of JavaScri...

Detailed explanation of custom events of Vue components

Table of contents Summarize <template> <...

Mobile browser Viewport parameters (web front-end design)

Mobile browsers place web pages in a virtual "...