作业

  1. 1. 先有一下成绩单数据
  2. scores = [
  3. { name: 'Bob', math: 97, chinese: 89, english: 67 },
  4. { name: 'Tom', math: 67, chinese: 52, english: 98 },
  5. { name: 'Jerry', math: 72, chinese: 87, english: 89 },
  6. { name: 'Ben', math: 92, chinese: 87, english: 59 },
  7. { name: 'Chan', math: 47, chinese: 85, english: 92 },
  8. ]
  9. table表格标签渲染以上数据,表格第一列是学生总分排名,最后一列是学生总分;
  10. 思路:逻辑都在js模块中,用scores变量保存,然后对这个socres进行遍历,把stu对象中的各个数据进行相加,然后用一个数组把加完的数据存起来,用于在表格中展示。
  11. 在模板中通过循环将stu对象展示出来,先展示索引,再展示对应的值
  12. 先通过冒泡排序,把total排序好,然后再展示
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <div id="app">
  9. <table border="1" width="400" rules="margin:auto">
  10. <tr>
  11. <th>排名</th>
  12. <th>姓名</th>
  13. <th>数学</th>
  14. <th>语文</th>
  15. <th>英语</th>
  16. <th>总分</th>
  17. </tr>
  18. <tr v-for="(stu,i) in scores">
  19. <td>{{ i+1}}</td>
  20. <td v-for="v in stu">{{ v}}</td>
  21. </tr>
  22. </table>
  23. </div>
  24. </body>
  25. <script src="js/vue.js"></script>
  26. <script>
  27. let scores = [
  28. {name: 'Bob', math: 97, chinese: 89, english: 67},
  29. {name: 'Tom', math: 67, chinese: 52, english: 98},
  30. {name: 'Jerry', math: 72, chinese: 87, english: 89},
  31. {name: 'Ben', math: 92, chinese: 87, english: 59},
  32. {name: 'Chan', math: 47, chinese: 85, english: 92},
  33. ];
  34. let total_scores = [];
  35. for (stu of scores){
  36. stu.total = stu.math + stu.chinese + stu.english;
  37. total_scores.push(stu);
  38. }
  39. for (let i=0;i<total_scores.length-1;i++){
  40. for (let j=0;j<total_scores.length-1-i;j++){
  41. if (total_scores[j].total<total_scores[j+1].total){
  42. let t=total_scores[j];
  43. total_scores[j] = total_scores[j+1];
  44. total_scores[j+1]=t;
  45. }
  46. }
  47. }
  48. console.log(total_scores);
  49. new Vue({
  50. el:'#app',
  51. data:{
  52. scores:total_scores,
  53. }
  54. });
  55. </script>
  56. </html>
  1. 2.用上面的数据,采用相同的渲染规则,只渲染所有科目都及格了的学生。
  2. 思路就是在for循环中加入一个if判断,将及格的数据都筛选出来展示
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <div id="app">
  9. <table border="1" width="400" rules="margin:auto">
  10. <tr>
  11. <th>排名</th>
  12. <th>姓名</th>
  13. <th>数学</th>
  14. <th>语文</th>
  15. <th>英语</th>
  16. <th>总分</th>
  17. </tr>
  18. <!--添加筛选条件-->
  19. <tr v-for="(stu,i) in scores" v-if="stu.math>60&&stu.chinese>60&&stu.english>60">
  20. <td>{{ i+1}}</td>
  21. <td v-for="v in stu">{{ v}}</td>
  22. </tr>
  23. </table>
  24. </div>
  25. </body>
  26. <script src="js/vue.js"></script>
  27. <script>
  28. let scores = [
  29. {name: 'Bob', math: 97, chinese: 89, english: 67},
  30. {name: 'Tom', math: 67, chinese: 52, english: 98},
  31. {name: 'Jerry', math: 72, chinese: 87, english: 89},
  32. {name: 'Ben', math: 92, chinese: 87, english: 59},
  33. {name: 'Chan', math: 47, chinese: 85, english: 92},
  34. ];
  35. let total_scores = [];
  36. for (stu of scores){
  37. stu.total = stu.math + stu.chinese + stu.english;
  38. total_scores.push(stu);
  39. }
  40. for (let i=0;i<total_scores.length-1;i++){
  41. for (let j=0;j<total_scores.length-1-i;j++){
  42. if (total_scores[j].total<total_scores[j+1].total){
  43. let t=total_scores[j];
  44. total_scores[j] = total_scores[j+1];
  45. total_scores[j+1]=t;
  46. }
  47. }
  48. }
  49. console.log(total_scores);
  50. new Vue({
  51. el:'#app',
  52. data:{
  53. scores:total_scores,
  54. }
  55. });
  56. </script>
  57. </html>
  1. 3.还是采用上方相同的数据,添加筛选规则:
  2. i)有三个按钮:语文、数学、外语,点击谁谁高亮,且当前筛选规则采用哪门学科
  3. ii)两个输入框,【】~【】,前面天最小分数,后面填最大分数,全部设置完毕后,表格的数据会被更新只渲染满足所有条件的结果
  4. 举例:点击语文,输入【86】~【87】,那就只会渲染JerryBen两条数据
  5. 思路:
  6. 1、点击高亮
  7. 首先应该给一个类,这个类设置一个高亮样式,然后把类绑定给按钮,但是要给一个k-v形式的类,v用于控制这个类是否为true(是否起作用),再一个是把按钮绑定一个点击事件(包着一个含有参数的方法,这个方法就是用于判断前面的类的样式是否显示),所以一个逻辑过程,就是鼠标点击按钮,会把参数传到vue中,再把当前的rule进行设置,于是就可以将类(对应的css样式)展示出来
  8. 2、输入框,筛选数据
  9. 输入框绑定的v-model,控制input中的value,然后输出的数据是在第一种的基础上面,加了v-if(逻辑实现输入框没有数据或只有一个有数据就会展示全部学生数据,在区间内,存在的数据),会把满足筛选条件的数据展示出来。
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style>
  7. .action {
  8. background-color: pink;
  9. }
  10. </style>
  11. </head>
  12. <body>
  13. <div id="app">
  14. <p style="margin: 10px auto; width: 400px">
  15. <button :class="{action: rule === 'chinese'}" @click="clickAction('chinese')">语文</button>
  16. <button :class="{action: rule === 'math'}" @click="clickAction('math')">数学</button>
  17. <button :class="{action: rule === 'english'}" @click="clickAction('english')">英语</button>
  18. <input type="number" min="1" max="100" v-model="min">
  19. ~
  20. <input type="number" min="1" max="100" v-model="max">
  21. </p>
  22. <table border="1" width="400" rules="all" style="margin: auto">
  23. <tr>
  24. <th>排名</th>
  25. <th>姓名</th>
  26. <th>数学</th>
  27. <th>语文</th>
  28. <th>英语</th>
  29. <th>总分</th>
  30. </tr>
  31. <tbody v-if="rule === 'math'">
  32. <tr v-for="(stu,i) in scores" v-if="(min && max && stu.math >= +min && stu.math <= +max) || (!min || !max)"> #
  33. <td>{{ i + 1 }}</td>
  34. <td v-for="v in stu">{{ v }}</td>
  35. </tr>
  36. </tbody>
  37. <!--第一步是筛选是否有高亮按钮-->
  38. <tbody v-else-if="rule === 'chinese'">
  39. <!--第一个and筛选框是否空,第二个筛选是否有在输入框间的数据,第三个||筛选是否一个有数据,一个没有数据-->
  40. <tr v-for="(stu,i) in scores" v-if="(min && max && stu.chinese >= +min && stu.chinese <= +max) || (!min || !max)">
  41. <td>{{ i + 1 }}</td>
  42. <td v-for="v in stu">{{ v }}</td>
  43. </tr>
  44. </tbody>
  45. <tbody v-else-if="rule === 'english'">
  46. <tr v-for="(stu,i) in scores" v-if="(min && max && stu.english >= +min && stu.english <= +max) || (!min || !max)">
  47. <td>{{ i + 1 }}</td>
  48. <td v-for="v in stu">{{ v }}</td>
  49. </tr>
  50. </tbody>
  51. <tbody v-else>
  52. <tr v-for="(stu,i) in scores">
  53. <td>{{ i + 1 }}</td>
  54. <td v-for="v in stu">{{ v }}</td>
  55. </tr>
  56. </tbody>
  57. </table>
  58. </div>
  59. </body>
  60. <script src="js/vue.js"></script>
  61. <script>
  62. let scores = [
  63. {name: 'Bob', math: 97, chinese: 89, english: 67},
  64. {name: 'Tom', math: 67, chinese: 52, english: 98},
  65. {name: 'Jerry', math: 72, chinese: 87, english: 89},
  66. {name: 'Ben', math: 92, chinese: 87, english: 59},
  67. {name: 'Chan', math: 47, chinese: 85, english: 92},
  68. ];
  69. let total_scores = [];
  70. for (stu of scores) {
  71. stu.total = stu.math + stu.chinese + stu.english;
  72. total_scores.push(stu);
  73. }
  74. for(let i = 0; i < total_scores.length - 1; i++) {
  75. for(let j = 0; j < total_scores.length - 1 - i; j++) {
  76. if (total_scores[j].total < total_scores[j+1].total) {
  77. let t = total_scores[j];
  78. total_scores[j] = total_scores[j+1];
  79. total_scores[j+1] = t;
  80. }
  81. }
  82. }
  83. console.log(total_scores);
  84. new Vue({
  85. el: '#app',
  86. data: {
  87. scores: total_scores,
  88. rule: '',
  89. min: '',
  90. max: '',
  91. },
  92. methods: {
  93. clickAction(rule) {
  94. this.rule = rule;
  95. }
  96. }
  97. });
  98. </script>
  99. </html>

day66test的更多相关文章

随机推荐

  1. day23_3_configparse

    #!/usr/bin/env python# -*- coding:utf-8 -*-# ------------------------------------------------------- ...

  2. 标记excel中输入的重复数据

    首先选中需要标记重复的数据列 开始 -> 条件格式 -> 突出显示单元格规则 -> 重复值 选择相应的颜色即可 效果如下:

  3. Spring Cloud Config的配置中心使用非对称性加密

    首先,我们需要通过keytool工具来生成密钥对. keytool是JDK中的一个密钥和证书管理工具.它使用户能够管理自己的公钥/私钥对及相关证书,用于(通过数字签名)自我认证(用户向别的用户/服务认 ...

  4. docker企业级镜像仓库harbor

    第一步:安装docker和docker-compose 第二步:下载harbor-offine-installer-v1.5.1.tgz 第三步:上传到/opt,并解压 第四步:修改harbor.cf ...

  5. 16.ajax_case08

    # 抓取简书博客总阅读量 # https://www.jianshu.com/u/130f76596b02 import requests import json import re from lxm ...

  6. 运算符的基本概念以及常用Scanner、随机数Random、选择结构的初步了解

    运算符 分类 算术运算符 位运算符 关系运算符|比较运算符 逻辑运算符 条件运算符 赋值运算符 其中优先级顺序从上到下,可以记忆口诀:单目乘除位关系,逻辑三目后赋值 操作数: 运算符左右两边的数 表达 ...

  7. DNA repair HDU - 2457 AC自动机+DP

    题意: 给你N个模板串,并且给你一个文本串, 现在问你这个文本串最少需要改变几个字符才能使得它不包含任何模板串. (以上字符只由A,T,G,C构成) 题解: 刚开始做这一题的时候表示很懵逼,好像没有学 ...

  8. java_初始网络编程

    /** * 网咯编程入门: *  c/s结构:全称Client/Server结构,是指客户端和服务器结构.常见程序有qq.迅雷等如那件 *  B/S结构:全称Browser/Server结构,是指浏览 ...

  9. Python全栈开发:socket代码实例

    客户端与服务端交互的基本流程 服务端server #!/usr/bin/env python # -*- coding;utf-8 -*- import socket sk = socket.sock ...

  10. Sky Code

    Sky Code 给出n个数,求选出4个数组合,使其gcd为1,,\(n<=10000\),每个数\(<=10000\). 解 理解1:容斥原理 注意到Mobius反演式子不好写出,于是我 ...