Home  >  Article  >  Web Front-end  >  How to hide or show elements in vue.js

How to hide or show elements in vue.js

王林
王林Original
2021-10-09 17:10:124692browse

Vue.js method of hiding or showing elements: Use the v-show directive to achieve this, for example [window.onload = function(){var vm = new Vue({el:'#box',data: {isShow:false,},metho...】.

How to hide or show elements in vue.js

The operating environment of this article: windows10 system, vue.js 2.9, thinkpad t480 computer.

In vue, if we want to control the hiding or display of elements, we can use the v-show directive.

The v-show directive is used to control the display or hiding of elements.

v-show="true/false" //控制元素显示/隐藏

Example:

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <meta charset="utf-8">
  <script src="http://unpkg.com/vue/dist/vue.js"></script>

  <script type="text/javascript">
    window.onload = function(){
      var vm = new Vue({
        el:&#39;#box&#39;,
        data:{
          isShow:false,
        },
        methods:{
          toggle:function(){
            this.isShow = !this.isShow;
          }
        }
      });
    }
  </script>
</head>
<body>
  <div id="box">
    <input type="button" value="toggle" v-on:click="toggle()"> <br />
    <div v-show="isShow" style="width: 100px;height: 100px;background: red"></div>
  </div>
</body>
</html>

Recommended learning:php training

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

Statement:
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