Get the App
SLTechnology News&Howtos  ›  Development  › 

How vuejs binds functions

Shulou Source: shulou.com Published: 2022-06-03 14:21:36 10月05日 Update

vuejs how to bind functions, I believe many inexperienced people are helpless about this, this article summarizes the causes and solutions of the problem, through this article I hope you can solve this problem.

vuejs binding function method: 1, use the form of "" to bind;2, use the form of "" to bind.

This tutorial operating environment: Windows 7 system, vue2.9.6 version, DELL G3 computer.

Event binding in vuejs is done using, where the function name is defined in the methods object in Vue instance, Vue instance can directly access the methods in it.

How events are bound

(1) Inline directly write js on the label to call the method

The first way to write an execution method

(2) Call methods defined in methods

The first way to write an execution method Short form of execution method export default { data () { return { msg: 'hello vue', list:[] } }, methods:{ run:function(){ alert ('this is a method'); } } }

Method parameters, method directly in the call when passing parameters in the method

Executing Method Transfer Value 111 Executing method passing value 2222 deleteData(val){ alert(val); },

Incoming Event Objects

event object eventFn(e){ console.log(e); // e.srcElement dom node e.srcElement.style.background='red'; console.log(e.srcElement.dataset.aid); /* Get custom attribute values */ After reading the above, do you know how vuejs binds functions? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

Tags: Methods functions events writing objects content examples forms more problems helpless for this hello reasons parameters for this properties skills tutorials methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MySQL Apple Microsoft Docker