ฉันผ่านพารามิเตอร์ในv-on:input
คำสั่ง ถ้าฉันไม่ผ่านมันฉันสามารถเข้าถึงเหตุการณ์ในวิธีการ มีวิธีใดบ้างที่ฉันยังสามารถเข้าถึงเหตุการณ์เมื่อส่งพารามิเตอร์ไปยังฟังก์ชัน ไม่ใช่ว่าฉันใช้ vue-router:
นี่คือโดยไม่ต้องผ่านพารามิเตอร์ ฉันสามารถเข้าถึงวัตถุเหตุการณ์
HTML
<input type="number" v-on:input="addToCart" min="0" placeholder="0">
จาวาสคริ
methods: {
addToCart: function (event) {
// I need to access the element by using event.target
console.log('In addToCart')
console.log(event.target)
}
}
นี่คือเมื่อผ่านพารามิเตอร์ ฉันไม่สามารถเข้าถึงวัตถุเหตุการณ์
HTML
<input type="number" v-on:input="addToCart(ticket.id)" min="0" placeholder="0">
จาวาสคริ
methods: {
addToCart: function (id) {
// How can I access the element by using event
console.log('In addToCart')
console.log(id)
}
}
นี่เป็นข้อมูลโค้ดบางส่วนควรดีพอที่จะทำซ้ำปัญหาที่ฉันมี
Property or method "event" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option