11- acquisition component content

<!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>获取组件内容</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app">
      <counter ref='one' @change='Add'></counter>
      <counter ref='two' @change='Add'></counter>
      <h1>总数{{total}}</h1>
    </div>
    <script>
        Vue.component('counter',{
            data:function() {
                 Return { 
                    Number: 0 
                } 
            }, 
            Template: ' <div = @ the Click "counterClick"> {{Number}} </ div> ' , 
            Methods: { 
                counterClick: function () { 
                    
                    the this .number ++ ; 
                    Console .log ( ' current value: ' + the this .number);
                     // subcomponent to its parent component by value 
                    the this . $ EMIT ( ' Change ' , the this  .number)
                }
            }
        })
        var app = new Vue({
            el:'#app',
            data:{
                total:0
            },
            methods: {
                Add:function(){
                        this.total = this.$refs.one.number +this.$refs.two.number;                       
                }
            },
        })
    
    </script>
</body>
</html>

 

Guess you like

Origin www.cnblogs.com/suni1024/p/11540215.html