D
D
DmitryGloom2018-08-10 11:28:30
Vue.js
DmitryGloom, 2018-08-10 11:28:30

How can I make it so that when clicking on the first checkbox, the subsequent ones would be blocked?

Good afternoon) Please help with the task) It is necessary that when you click on the first checkbox, the other two are blocked

<div id="app">
    
    <useredit></useredit>
    <userinfo></userinfo>
</div>
<script>

var eventBus = new Vue();
 
Vue.component('useredit', { 
    props: ["user"],
    template:  `<div>
                    <label v-for="n in items"> <input  v-model="n.checked" type="checkbox" :disabled="!block">
                </div>`,
    data() {
    return {
      items:[
        { value: [1, 1], checked: false, message: 'Шаблон'},
      ],
    }
  },
    methods:{
        block(){
            eventBus.$emit("userchange", this.items);
        },
    }
});
Vue.component('userinfo', { 
    props: ["user"],
    template: '<div><label v-for="n in items"> <input  v-model="n.checked" type="checkbox" :disabled="created"></div>',
    data() {
    return {
      items:[
        { value: [1, 1], checked: false, message: 'Шаблон', disabled: false},
        { value: [1, 1], checked: false, message: 'Шаблон', disabled: false},
        { value: [1, 1], checked: false, message: 'Шаблон', disabled: false},
      ],
    }
  },
    created(){
        eventBus.$on("userchange", (name)=>{
            this.items = !this.items;
        });
    }
});


new Vue({
    el: "#app",
    data:{
        
    }
});


</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-08-10
@DmitryGloom

It is possible to communicate components through an event bus .
Or through a common parent .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question