0

How can I make it in vue.js, if Option A is selected div b disable, and when Option B is selected div A is disable using Vue.js.

<div id="app">

    <select>

        <option>A</option>

        <option>B</option>

    </select>

    <div id="a">

            A

    </div>

    <div id="b">

            B

    </div>
1
  • 1
    It doesn't make sense to disable a div. The disabled attribute is only relevant for input-like elements. See the full list: w3schools.com/tags/att_disabled.asp Commented Jun 19, 2017 at 7:34

2 Answers 2

2

Firstly, you should search Vue's Methods.

Updated: 19/06/2017 - 16:35

And if you want to code sample you can use this to example:

var app = new Vue({
    el: '#app',
    data: {
        selected: ''
    },
})
#a {
    width: 128px;
    height: 128px;
    background-color: gray;
}

#b {
    width: 128px;
    height: 128px;
    background-color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js"></script>
<div id="app">
    <select v-model="selected">
        <option disabled value="">Select div name</option>
        <option value="a">A</option>
        <option value="b">B</option>
    </select>
    <div id="a" v-if="selected === 'a'">
      Div A
    </div>
    <div id="b" v-else>
      Div B
    </div>
</div>

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

3 Comments

This is not utilizing vue very much.
@BertEvans Yes you're right. I changed my code. He can use v-if and v-else. I think, Vue not just a template. So, if we need some JS code, we can use even if it is very simple.
@MathewMagante if this codes ok, you can mark as solved.
0

If by disabling you mean to hide id or remove it from DOM - yes, you can do it with Vue.

Applies to both: 1. Assign the select to the model like v-model='selected' 2. Initiate it in the model: data() { return { selected: null; (...) } }

v-if - DIV will be removed/insterted from/into DOM

  1. On your divs: <div id='a' v-if="selected=== 'a'"

v-show - div will be hidden/shown

  1. On your divs: <div id='a' v-show="selected=== 'a'"

2 Comments

SO is not free coding service. You should try to do that by yourself. It is really simple job. You will learn much more doing it by yourself. I gave you solution for your question. vuejs.org/v2/guide/index.html
@MathewMagante Read the Vuejs guide and you will understand after awhile. It's better to write the code yourself than spoonfed. It's for your own good too!

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.