• 671 vue条件渲染


    条件渲染


    v-if、v-else、v-else-if


    template元素


    v-show


    v-show和v-if的区别


    01_条件渲染的基本使用.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    </head>
    <body>
      
      <div id="app"></div>
    
      <template id="my-app">
        <h2 v-if="isShow">哈哈哈哈</h2>
        <button @click="toggle">切换</button>
      </template>
    
      <script src="../js/vue.js"></script>
      <script>
        const App = {
          template: '#my-app',
          data() {
            return {
              message: "Hello World",
              isShow: true
            }
          },
          methods: {
            toggle() {
              this.isShow = !this.isShow;
            }
          }
        }
    
        Vue.createApp(App).mount('#app');
    
        // JavaScript条件判断
        if (true) {
    
        }
      </script>
    </body>
    </html>
    

    02_多个条件的渲染.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    </head>
    <body>
      <div id="app"></div>
    
      <template id="my-app">
        <input type="text" v-model="score">
        <h2 v-if="score > 90">优秀</h2>
        <h2 v-else-if="score > 60">良好</h2>
        <h2 v-else>不及格</h2>
      </template>
    
      <script src="../js/vue.js"></script>
      <script>
        const App = {
          template: '#my-app',
          data() {
            return {
              score: 95
            }
          }
        }
    
        Vue.createApp(App).mount('#app');
      </script>
    </body>
    </html>
    

    03_template和v-if结合使用.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    </head>
    <body>
      <div id="app"></div>
    
      <template id="my-app">
        <template v-if="isShowHa">
          <h2>哈哈哈哈</h2>
          <h2>哈哈哈哈</h2>
          <h2>哈哈哈哈</h2>
        </template>
    
        <template v-else>
          <h2>呵呵呵呵</h2>
          <h2>呵呵呵呵</h2>
          <h2>呵呵呵呵</h2>
        </template>
      </template>
    
      <script src="../js/vue.js"></script>
      <script>
        const App = {
          template: '#my-app',
          data() {
            return {
              isShowHa: true
            }
          }
        }
    
        Vue.createApp(App).mount('#app');
      </script>
    </body>
    </html>
    

    04_v-show的条件渲染.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    </head>
    <body>
      <div id="app"></div>
    
      <template id="my-app">
        <h2 v-show="isShow">哈哈哈哈</h2>
      </template>
    
      <script src="../js/vue.js"></script>
      <script>
        const App = {
          template: '#my-app',
          data() {
            return {
              isShow: true
            }
          }
        }
    
        Vue.createApp(App).mount('#app');
      </script>
    </body>
    </html>
    

    05_v-show和v-if的区别.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    </head>
    <body>
      <div id="app"></div>
    
      <template id="my-app">
        <h2 v-if="isShow">哈哈哈哈</h2>
        <h2 v-show="isShow">呵呵呵呵</h2>
      </template>
    
      <script src="../js/vue.js"></script>
      <script>
        const App = {
          template: '#my-app',
          data() {
            return {
              isShow: true
            }
          }
        }
    
        Vue.createApp(App).mount('#app');
      </script>
    </body>
    </html>
    
  • 相关阅读:
    Centos7 FTP服务安装,Centos FTP安装配置
    Shiro CookieRememberMeManager Invalid AES key length
    Shiro thymeleaf整合使用
    闪存中的键值对:无文件系统 minINI
    SAP UI类标准导出XML格式Excel
    CRM item status error
    被某个自认漂亮国的狗腿子骂了。。。
    New ABAP Debugger Session does not close after Exit
    Java队列使用举例
    布隆过滤器使用举例
  • 原文地址:https://www.cnblogs.com/jianjie/p/14780006.html
Copyright © 2020-2023  润新知