详细参考官方文档:
https://cn.vuejs.org/v2/guide/conditional.html
https://cn.vuejs.org/v2/guide/list.html
https://cn.vuejs.org/v2/guide/class-and-style.html
https://cn.vuejs.org/v2/guide/conditional.html
https://cn.vuejs.org/v2/guide/list.html
https://cn.vuejs.org/v2/guide/class-and-style.html
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Vue入门, 条件渲染,列表渲染,style绑定,class绑定</title>
- <script src="https://cdn.bootcss.com/vue/2.5.18/vue.min.js"></script>
- </head>
- <body>
- <div id="app">
- <!-- 1.条件渲染 -->
- <div v-if="score >= 90"> 优秀 </div>
- <div v-else-if="score < 90 && score >= 70"> 良好 </div>
- <div v-else-if="score < 70 && score >= 60"> 一般 </div>
- <div v-else> 不合格 </div>
- <!-- v-show和v-if相似,但是也有区别 -->
- <div v-show="score > 90">优秀</div>
- <!-- 2.列表渲染 -->
- <table border="1px solid #ccc;">
- <tr>
- <td>姓名</td>
- <td>年龄</td>
- </tr>
- <tr v-for="item in list">
- <td>{{item.name}}</td>
- <td>{{item.age}}</td>
- </tr>
- </table>
- <!-- 3.style绑定 -->
- <div :style="goodStudent">{{msg}}</div>
- <!-- 4.class绑定,都会有post和post-page;当commentSize>20,会加hot -->
- <div :class="['post','post-page', {'hot': commentSize > 20}]"></div>
- </div>
- <script>
- var app = new Vue({
- el: '#app',
- data: {
- score: 96,
- list: [{
- name: '小曌瞾',
- age: '18'
- },{
- name: '小凯凯',
- age: '8'
- },{
- name: '小琪琪',
- age: '12'
- }],
- msg: "我是小曌瞾",
- goodStudent: {
- color: 'red',
- textShadow: '0 0 5px yellow'
- },
- commentSize: 35
- },
- })
- </script>
- </body>
- </html>
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏