How to hide content in vue

藏色散人
Release: 2022-12-26 15:43:59
Original
2660 people have browsed it

Vue method of hiding content: 1. Add "v-show" to the content div that needs to be hidden or displayed; 2. Add a click event to the div of the iconfont icon; 3. Wrap it with transition at × , and add the name attribute; 4. Add an effect style to the fade.

How to hide content in vue

#The operating environment of this tutorial: Windows 10 system, Vue version 3, Dell G3 computer.

vue How to hide content?

vue implements the function of clicking on a div to appear and hide content

1. First add v-show to the content div that needs to be hidden or displayed, which represents Determine whether to show or hide

<div  v-show="shopShow">内容</div>
Copy after login

2. Here I have a × sign in the open content to turn off the display effect, and add a click event to the div of the iconfont icon

<div  @click="toggleShopShow">
            <span class="iconfont icon-close"></span>
</div>
Copy after login

3. In export The code in default is as follows

 export default {
    data () {
      return {
        shopShow: false, //默认内容不显示
      }
    },
    methods: {
      toggleShopShow () {
        this.shopShow = !this.shopShow //使false变为true显示
      },
    }
  }
</script>
Copy after login

to achieve

4. Add a transition animation effect to hide it, as follows

Wrap the × with transition and add the name attribute

<transition name="fade">
 <div class="activity-sheet-close" @click="toggleSupportShow">
            <span class="iconfont icon-close"></span>
 </div>         
 </transition>
Copy after login

Add effect style to fade, add

&.fade-enter-active,&.fade-leave-active
        transition opacity .8s
&.fade-enter,&.fade-leave-to
        opacity 0
Copy after login

in style to achieve

Recommended learning: "vue.js video tutorial"

The above is the detailed content of How to hide content in vue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
vue
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!