Vue basic introduction note 12: component switching


Vue basic introduction notes 12

  • Component placeholder: is sets the component to render
<!DOCTYPE html>
<html lang="en">

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src=""></script>
    <link rel="stylesheet" href="[email protected]/dist/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <div id="app">
        <div role="tabpanel">
            <!-- Nav tabs -->
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active">
                    //Click different tabs to switch between different components
                    <a href="#home" @click.prevent="componentName = 'tabpanel1'" aria-controls="home" role="tab"
                <li role="presentation">
                    <a href="#tab" @click.prevent="componentName = 'tabpanel2'" aria-controls="tab" role="tab"
            <!-- Tab panes -->
            <div class="tab-content">
            //Component placeholder  
            <component :is="componentName"></component>
    <template id="tab1">
    <template id="tab2">
        //Define two components
        Vue.component('tabpanel1', {
            template: '#tab1'
        Vue.component('tabpanel2', {
            template: '#tab2'
        var vm = new Vue({
            el: '#app',
            data: {
                //Default to the first component
                componentName: 'tabpanel1'
            methods: {}
        Vue.config.devtools = true


This work adoptsCC agreement, reprint must indicate the author and the link to this article

Purple smoke from sunshine censer

Recommended Today

permutation – full permutation

full permutation problem Topic description output natural numbers in lexicographical order\(1\)arrive\(n\)All non-repeating permutations, i.e.\(n\)The full permutation of , requires that no duplicate digits are allowed in any sequence of digits generated. input format an integer\(n\)。 output format Depend on\(1 \sim n\)Consists of all distinct sequences of numbers, one sequence per line. reserved for each number\(5\)field […]