v-on的参数传递

  <div id="app">
        <button type="button" @click="btn('123')">+</button>
        <button type="button" @click="btn()">+</button>
        <button type="button" @click="btn">+</button>
        <button type="button" @click="btn($event,'333')">+</button>
        <button type="button" @click="btn2($event)">+2</button>
    </div>
    <script src="vue.js"></script>
    <script>
        const app = new Vue({
                el: "#app",
                data() {
                    return {}
                },
                methods: {
                    /* btn(value) {
                    	console.log(value);
                    } */

                    btn(e, value) {
                        console.log(e);
                        console.log(value);
                    },
                    btn2(e) {
                        console.log(e);
                    }

                },
                computed: {

                }
            })
            /* 	1.如需要传参 在页面中传的是实参 在methods中写的是形参.
			2.如果在页面中没有写实参但是留有括号 在在methods中写了形参 会打印undefined
			3.如果在页面中没有写实参也没有留有括号 在在methods中写了形参 会打印event 
			4.如果你想同时传事件和参数 在页面中那就要第一参数写$event,第二个是参数
			5.如果你只传事件 那么在页面中可以完全不写括号 或者btn2($event)*/
    </script>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值