Skip to content
Advertisement

How to hide content when clicked checkbox from different components in vuejs?

JavaScript
JavaScript
JavaScript

How to hide content of checkbox from different components in Vuejs

I have three components called inputone(contains checkbox with v-model),inputtwo (contains checkbox with v-model),maincontent.(having some content and logic), So when user click on checkboxes from either one checckbox(one,two). i schould hide the content.

Codesanfdbox link https://codesandbox.io/s/crimson-fog-wx9uo?file=/src/components/maincontent/maincontent.vue

reference code:- https://codepen.io/dhanunjayt/pen/mdBeVMK

Advertisement

Answer

You are actually not syncing the data between components. The main content checked never changes. You have to communicate data between parent and child components or this won’t work. And try using reusable components like instead of creating inputone and inputtwo for same checkbox create a generic checkbox component and pass props to it. It is a good practice and keeps the codebase more manageable in the longer run.

App.vue

JavaScript

checkbox component:

JavaScript

Content:

JavaScript

https://codesandbox.io/embed/confident-buck-kith5?fontsize=14&hidenavigation=1&theme=dark

Hope this helps and you can learn about passing data between parent and child components in Vue documentation: https://v2.vuejs.org/v2/guide/components.html

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement