0

I have got this in my html code

<div class="pl_wrapper">
    <div class="options_pl">
        <input type="button" @click="optionButtonClicked" class="option_button_pl" value="List">
        <input type="button" @click="optionButtonClicked" class="option_button_pl" value="Add a language">
    </div>
    {{show2}}
</div>

And this in my vue.js

const ProgrammingLanguages = new Vue({
            el:".pl_wrapper",
            data:{
                name: "aa",
                show1: false,
                show2: false
            },
            methods: {
                optionButtonClicked(){
                    var indexOfClicked  = index(event.target,event.target.className);
                    var equalIndexOfDiv = getOnIndex(indexOfClicked,"pl_divs")
                    $(".options_pl").hide();
                    show1 = (indexOfClicked==0) ? true : false
                    show2 = (indexOfClicked==1) ? true : false
                }
            }
        });

Now when i click option_button_pl i expect {{show2}}'s to also change from false to true and vice versa.But alas that doesn't Jsfiddle: happen.https://jsfiddle.net/3akfzcyf/

3
  • you need to reference the component's data like this.show1, this.show2, etc. I'd read through the docs: vuejs.org/v2/guide Commented Aug 21, 2017 at 20:13
  • Look at the browser console. You have a bunch of errors. Commented Aug 21, 2017 at 20:14
  • @SLaks i don't see a single one Commented Aug 21, 2017 at 20:15

2 Answers 2

1

you have to use the this keyword. Something like this.show1 and this.show2

Sign up to request clarification or add additional context in comments.

Comments

1

here is your code working and I updated your fiddle Adding the this statement and adding the event param inside optionButtonClicked

const ProgrammingLanguages = new Vue({
            el:".pl_wrapper",
            data:{
                name: "aa",
                show1: false,
                show2: false
            },
            methods: {
                optionButtonClicked(event){
                    var indexOfClicked  = index(event.target,event.target.className);
                    this.show1 = (indexOfClicked==0) ? true : false
                    this.show2 = (indexOfClicked==1) ? true : false
          console.log(this.show2)
                }
            }
        });
        function index(element,className){
        var allElements = document.getElementsByClassName(className);
        for (var i = 0; i < allElements.length; i++) {
            if(allElements[i]==element){
                return i;
            }
        }
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.