image.png

代码

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue.js中指令对应函数参数的几种使用方式</title>
    <script src="//static.gzj2001.com/vue/vue.js"></script>
</head>
<body>
    <div id="app">
        <button v-on:click="x1+=1">加1</button>
        <div>{{x1}}</div>
        <button @click="add">加1</button>
        <div>{{x2}}</div>
        <button @click="add2(x1,x2)">1和2按钮的总和</button>
        <div>{{x3}}</div>
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                x1:0,
                x2:0,
                x3:0
            },
            methods:{
                add:function(){
                    this.x2=this.x2+1;
                },
                add2:function(cs1,cs2){
                    this.x3=cs1+cs2;
                }
            }
        })
    </script>
</body>
</html>