一.组件是可以重复使用的,而且它用起来很方便。
1.首先它有三个主要步骤:
(1),定义组件
(2),注册组件
(3),使用组件
2.使用组件是在HTML带码里面使用,注册组件和定义组件都是在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>注册组件到Vue的实例</title>
    <script src="../JS/vue.js"></script>
</head>
<body>
    <!-- 使用组件 -->
    <div id="app">
        <button-counter></button-counter>
        <button-counter></button-counter>
        <button-counter></button-counter>
    </div>
    <script>
        //定义组件
        var compoent1 = {
            data: function() {
                return {
                    count: 0
                }
            },
            template: '<button @click="count++">点击了{{ count }} 次.</button>'
        }
        //注册组件
        Vue.component("button-counter", compoent1);
            var vm = new Vue({
                 el: "#app"
            });
    </script>
             
   
</body>
</html>
二
 
                            