How do use vue2.0 with jquery onclick event method ? As i research on the particular question with defining an mounted of this.$el.addEventListener('click', this.onClick) on vue . but seems not really clear for me . I need an help from here. Kindly advise
As my code below jquery :
$(document).on("click",".ballNum li",function(){
var robj = $(this);
var value = robj.text();
var bit = $(this).parents(".ballNum").attr("id");
if(robj.attr("name")=="choice"){
robj.removeAttr("name");
}else{
robj.attr("name","choice");
}
var isSave = saveNum(value,bit,"reverse");
if(isSave==1){
$(this).addClass("active");
}else if(isSave==-1){
$(this).removeClass("active");
}else{
layer.alert('Error',{icon: 0, title:'Alert'});
}
You would need to first understand the basic difference between jQuery and VueJS. Everything that you do in jQuery can be done in VueJS, it is just a matter of understanding the difference. When we are in the jQuery land, we are habituated to the
$()
to fetch the values and stuff.VueJS is different, here, there is reactivity at the backend, the library takes care of the complete html. You have to define the html, using the Vue syntax, then define the data array, which stores the variables. The variables are then used inside the templates
This would print "do something!" thrice.
This is the modifications we can do to the above block, after adding the input tag, here is your 'click' method, rather than use jQuery's click method, we use the one which Vue provides.
Vue's click method executes Vue's
AddToDo
function.What this will enable you is this:
For more details, read this: https://github.com/thewhitetulip/intro-to-vuejs/
I would guess something like this:
<button v-on:click="greet">Greet</button>
Then in a Vue component:
Then put your code from your method into the greet method.
But, I would start with learning some Vue.js by working through their documentation.
Mick