Vue中的全局组件

<!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>
<body>
    <div id="app">
<my-component>  </my-component>

    </div>
    <template id="my-component-template">
        <div>
            <ul>
                <li><a href="">首页</a></li>
                <li><a href="">产品</a></li>
                <li><a href="">公司简介</a></li>
                <li><a href="">联系我们</a></li>
                {{msg}}
            </ul>
        </div>
    </template>
    <script src="vue.js"></script>
    <script>
        //定义全局组件
     Vue.component('my-component',{
        template:'#my-component-template',
           data(){
               return{
                   msg:'我是全局组件'
               }
           }
        })


        var vm=new Vue({
            el:'#app',
            data:{
                message:'Hello Vue.js!'
            }

        })
    </script>
</body>
</html>
posted @ 2024-09-12 14:31  一个人走在路上  阅读(2)  评论(0编辑  收藏  举报