zoukankan      html  css  js  c++  java
  • vue---条件与循环语句

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>vue--循环语句</title>
    <script src="https://static.runoob.com/assets/vue/1.0.11/vue.min.js"></script>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    </head>

    <body>
    <div id="app">
    <p v-if="seen">
    看下我
    <template v-if="ok">
    <h1>悟空</h1>
    <p>
    三打白骨精
    </p>
    {{#if ok}}
    <h1>yes</h1>
    {{/if}}
    </template>

    </p>

    </div>

    <!--v-else-->
    <div id="else">
    <!--Math.random()取随机数-->
    <div v-if="Math.random()>0.5">
    sorry
    </div>
    <div v-else>
    welcome
    </div>
    </div>


    <!--v-else-if-->
    <div id="elseif">
    <div v-if="type === 'A'">
    A
    </div>
    <div v-else-if="type === 'B'">
    B
    </div>
    <div v-else-if="type === 'C'">
    C
    </div>
    <div v-else>
    Not A/B/C
    </div>
    </div>
    <!--v-for 指令需要以 site in sites 形式的特殊语法,
    sites 是源数据数组并且 site 是数组元素迭代的别名。-->
    <div id="vfor">
    <ol>
    <li v-for="dog in dogs">
    {{dog.name}}<br>
    --------------
    </li>
    </ol>
    <ul>
    <template v-for="dog in dogs">
    <li>{{ dog.name }}</li>
    <li>--------------</li>
    </template>
    </ul>
    </div>


    <div id="forobj">
    <ul>
    <li v-for="value in object">
    {{ value }}
    </li>
    </ul>
    <ul>
    <li v-for="(value,key) in object">
    {{key}}:{{ value }}
    </li>
    </ul>
    <ul>
    <li v-for="(value,key,index) in object">
    {{index}}: {{key}}:{{ value }}
    </li>
    </ul>
    </div>
    <div id="forint">
    <ul>
    <li v-for="n in 10"> {{n}}</li>
    </ul>
    </div>
    </body>
    <script>
    <!--v-for 迭代对象-->
    new Vue({
    el:'#forint'
    })
    </script>

    <script>
    <!--v-for 迭代对象-->
    new Vue({
    el:'#forobj',
    data:{
    object:{
    name:'悟空',
    race:'猴子',
    address:'花果山',
    post:'美猴王'
    }
    }
    })
    </script>
    <script>

    <!--v-for -->
    new Vue({
    el:'#vfor',
    data:{
    dogs:[
    {name:'泰迪'},
    {name:'二哈'},
    {name:'金毛'},
    {name:'藏獒'},
    ]
    }
    })
    </script>

    <script>
    <!--v-else-if-->
    new Vue({
    el:'#elseif',
    data:{
    type:'A'
    }
    })
    </script>

    <script>
    <!--v-else-->
    new Vue({
    el:'#else',
    })
    </script>


    <script>
    new Vue({
    el:'#app',
    data:{
    seen:true,
    ok:false
    }
    })
    </script>

    </html>

  • 相关阅读:
    Verilog HDL的程序结构及其描述
    VerilogHDL概述与数字IC设计流程学习笔记
    常用算法与设计模式
    DOM笔录
    JavaScript笔录
    Windows系统版本型号MSDN版、OEM版、RTM版、VOL版区别
    Yaml学习笔录
    Linux关闭iptables以及selinux
    Centos配置163YUM源
    utf8 和 UTF-8 在使用中的区别
  • 原文地址:https://www.cnblogs.com/cxiang/p/10551307.html
Copyright © 2011-2022 走看看