首页 > 其他 > 详细

441 vue内置组件component

时间:2020-04-13 18:17:49      阅读:59      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>Document</title>
</head>

<body>
    <!-- 
       component 内置组件
     -->

    <div id="app">
        <button @click="fn(‘one‘)">One</button>
        <button @click="fn(‘two‘)">Two</button>

        <!-- 
        is : 负责显示哪个组件
        值 : 组件的名称 , name 
       -->
        <component :is="componentName">
            <one></one>
            <two></two>
        </component>
    </div>

    <script src="./vue.js"></script>
    <script>
        Vue.component(‘one‘, {
            name: ‘one‘,
            template: `<div>子组件one</div>`
        })
        
        Vue.component(‘two‘, {
            name: ‘two‘,
            template: `<div>子组件two</div>`
        })

        const vm = new Vue({
            el: ‘#app‘,
            data: {
                componentName: ‘one‘
            },
            methods: {
                fn(name) {
                    this.componentName = name
                }
            }
        })
    </script>
</body>

</html>

441 vue内置组件component

原文:https://www.cnblogs.com/jianjie/p/12692980.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!