谷粒学院_day03_vue组件

组件的作用就是用来将一些可以复用的代码抽取出来的,有单页面组件和全局组件,单页面组件的话是定义在一个html页面的,只能本页面使用;而全局组件是定义在单独的js文件中,只要引入该js文件,就能使用该组件了

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <component1></component1>
        <component2></component2>
    </div>
    <script src="jsvue.min.js"></script>
    <script src="components/navbar.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                
            },
            components: {
                'component1':{
                    template:'<h1>我很牛逼</h1>'
                }
            }
        })
    </script>
</body>

</html>
navbar.js文件:
Vue.component('component2',{
    template: '<ul><li>huya</li><li>douyu</li></ul>'
})
 
原文地址:https://www.cnblogs.com/ibcdwx/p/14126776.html