vue.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>
    <script src="./vue.js"></script>
</head>
<body>
    <div id="app">
        点击次数:{{counter}}
        <br/>
        <button @click="handleAdd()">+1</button>
        <button @click="handleAdd(10)">+10</button>
    </div>
    <script>
        new Vue({
            el:'#app',
            data:{
                counter:0
            },
            methods:{
                handleAdd:function(count){
                   count=count || 1;   //默认1
                    this.counter+=count;
                }
            }
        })
    </script>
</body>
</html>

 

posted @ 2019-02-21 11:15  聂小恶  阅读(9508)  评论(0编辑  收藏  举报