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

Perfect solution for theme switching based on Css Variable (recommended)

When receiving this requirement, Baidu found many...

The pitfall of MySQL numeric type auto-increment

When designing table structures, numeric types ar...

The pitfalls and solutions caused by the default value of sql_mode in MySQL 5.7

During normal project development, if the MySQL v...

The difference and execution method of select count() and select count(1)

Count(*) or Count(1) or Count([column]) are perha...

How to Apply for Web Design Jobs

<br />Hello everyone! It’s my honor to chat ...

JavaScript to achieve simple tab bar switching case

This article shares the specific code for JavaScr...

How to use Docker-compose to deploy Django applications offline

Table of contents Install Docker-ce for the devel...

Detailed explanation of the difference between $router and $route in Vue

We usually use routing in vue projects, and vue-r...

How to quickly install tensorflow environment in Docker

Quickly install the tensorflow environment in Doc...

Summary of the pitfalls of using primary keys and rowids in MySQL

Preface We may have heard of the concept of rowid...