A
A
Anton2017-07-12 10:54:05
JavaScript
Anton, 2017-07-12 10:54:05

How to execute a function only when the checkbox is set to true?

Good day everyone!
Prompt how to implement switching between two functions.
I have two plugins d3 and Snap.svg, how to make it so that when the checkbox is enabled, d3 is executed and when snap.svg is disabled.

svg: function (){
   this.d3()
   this.svgSnap()
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor Koch, 2017-07-12
@amux

create a variable in data: Put v-model on the checkbox and use it in the method

svg: function (){
  if(this.isD3JS){
    this.d3()
  }else{
    this.svgSnap()
  }
}

It is possible to take an element by id, as the answer above gave, but using Vue it does not work correctly.

N
Nikolai Kargin, 2017-07-12
@kgnk

if(document.getElementById("someElement").checked){
// Очевидно, что если проставлен
}else{
// Очевидно, что если не проставлен
}

A
Anton Anton, 2017-07-12
@Fragster

Make two child components, one with d3, one with svgsnap, drive them to a variable and v-if v-else

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question