前端-vue基础57-局部组件注册

 

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<div id="app">
    <hello-world></hello-world>
    <hello-tom></hello-tom>
    <hello-geyao></hello-geyao>
    <test-com></test-com>
</div>
 
<body>
    <script type="text/javascript" src="./js/vue.js"></script>
    <script>
        Vue.component('test-com', {
            template: '<div>Test</div>'
        })
        var HelloWorld = {
            data: function() {
                return {
                    msg: 'HelloWorld'
                }
            },
            template: '<div>{{msg}}</div>'
        };
        var HelloTom = {
            data: function() {
                return {
                    msg: 'HelloTom'
                }
            },
            template: '<div>{{msg}}</div>'
        };
        var HelloGeyao = {
            data: function() {
                return {
                    msg: 'HelloGeyao'
                }
            },
            template: '<div>{{msg}}</div>'
        };
        var vm = new Vue({
            el: '#app',
            data: {
 
            },
            components: {
                'hello-world': HelloWorld,
                'hello-tom': HelloTom,
                'hello-geyao': HelloGeyao
            }
        });
    </script>
</body>
 
</html>

 

posted @ 2022-07-23 22:30  前端导师歌谣  阅读(69)  评论(0)    收藏  举报