Vue作业2

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <div id="app">
        <table border="1" width="400" rules="all" style="margin: auto">
            <tr>
                <th>排名</th>
                <th>姓名</th>
                <th>数学</th>
                <th>语文</th>
                <th>英语</th>
                <th>总分</th>
            </tr>
            <tr v-for="(stu,i) in scores">
                <td>{{ i + 1 }}</td>
                <td v-for="v in stu">{{ v }}</td>
            </tr>
        </table>
    </div>
</body>
<script src="js/vue.js"></script>
<script>
    let scores = [
        {name: 'Bob', math: 97, chinese: 89, english: 67},
        {name: 'Tom', math: 67, chinese: 52, english: 98},
        {name: 'Jerry', math: 72, chinese: 87, english: 89},
        {name: 'Ben', math: 92, chinese: 87, english: 59},
        {name: 'Chan', math: 47, chinese: 85, english: 92},
    ];

    let total_scores = [];
    for (stu of scores) {
        stu.total = stu.math + stu.chinese + stu.english;
        total_scores.push(stu);
    }



    for(let i = 0; i < total_scores.length - 1; i++) {
        for(let j = 0;  j < total_scores.length - 1 - i; j++) {
            if (total_scores[j].total < total_scores[j+1].total) {
                let t = total_scores[j];
                total_scores[j] = total_scores[j+1];
                total_scores[j+1] = t;
            }
        }
    }
    console.log(total_scores);



    new Vue({
        el: '#app',
        data: {
            scores: total_scores,
        }
    });



    let arr = [1, 4, 2, 5, 3];
    for (let i=0; i < 5 - 1; i++) {
        for (let j=0; j < 5 - 1 - i; j++) {
            if (arr[j] > arr[j+1]) {

                let t = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = t;
            }
        }
    }
    console.log(arr);
</script>
</html>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <div id="app">
        <table border="1" width="400" rules="all" style="margin: auto">
            <tr>
                <th>排名</th>
                <th>姓名</th>
                <th>数学</th>
                <th>语文</th>
                <th>英语</th>
                <th>总分</th>
            </tr>
            <tr v-for="(stu,i) in scores" v-if="stu.math>60&&stu.chinese>60&&stu.english>60">
                <td>{{ i + 1 }}</td>
                <td v-for="v in stu">{{ v }}</td>
            </tr>
        </table>
    </div>
</body>
<script src="js/vue.js"></script>
<script>
    let scores = [
        {name: 'Bob', math: 97, chinese: 89, english: 67},
        {name: 'Tom', math: 67, chinese: 52, english: 98},
        {name: 'Jerry', math: 72, chinese: 87, english: 89},
        {name: 'Ben', math: 92, chinese: 87, english: 59},
        {name: 'Chan', math: 47, chinese: 85, english: 92},
    ];

    let total_scores = [];
    for (stu of scores) {
        stu.total = stu.math + stu.chinese + stu.english;
        total_scores.push(stu);
    }



    for(let i = 0; i < total_scores.length - 1; i++) {
        for(let j = 0;  j < total_scores.length - 1 - i; j++) {
            if (total_scores[j].total < total_scores[j+1].total) {
                let t = total_scores[j];
                total_scores[j] = total_scores[j+1];
                total_scores[j+1] = t;
            }
        }
    }
    console.log(total_scores);



    new Vue({
        el: '#app',
        data: {
            scores: total_scores,
        },

    });


</script>
</html>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        .action {
            background-color: pink;
        }
    </style>
</head>
<body>
    <div id="app">
        <p style="margin: 10px auto;  400px">
            <button :class="{action: rule === 'chinese'}" @click="clickAction('chinese')">语文</button>
            <button :class="{action: rule === 'math'}" @click="clickAction('math')">数学</button>
            <button :class="{action: rule === 'english'}" @click="clickAction('english')">英语</button>
            <input type="number" min="1" max="100" v-model="min">
            ~
            <input type="number" min="1" max="100" v-model="max">
        </p>

        <table border="1" width="400" rules="all" style="margin: auto">
            <tr>
                <th>排名</th>
                <th>姓名</th>
                <th>数学</th>
                <th>语文</th>
                <th>英语</th>
                <th>总分</th>
            </tr>
            <tbody v-if="rule === 'math'">
                <tr v-for="(stu,i) in scores" v-if="(min && max && stu.math >= +min && stu.math <= +max) || (!min || !max)">
                    <td>{{ i + 1 }}</td>
                    <td v-for="v in stu">{{ v }}</td>
                </tr>
            </tbody>
            <tbody v-else-if="rule === 'chinese'">
                <tr v-for="(stu,i) in scores" v-if="(min && max && stu.chinese >= +min && stu.chinese <= +max) || (!min || !max)">
                    <td>{{ i + 1 }}</td>
                    <td v-for="v in stu">{{ v }}</td>
                </tr>
            </tbody>
            <tbody v-else-if="rule === 'english'">
                <tr v-for="(stu,i) in scores" v-if="(min && max && stu.english >= +min && stu.english <= +max) || (!min || !max)">
                    <td>{{ i + 1 }}</td>
                    <td v-for="v in stu">{{ v }}</td>
                </tr>
            </tbody>
            <tbody v-else>
                <tr v-for="(stu,i) in scores">
                    <td>{{ i + 1 }}</td>
                    <td v-for="v in stu">{{ v }}</td>
                </tr>
            </tbody>
        </table>

        <div v-if="'1'==1">1111</div>
    </div>
</body>
<script src="js/vue.js"></script>
<script>
    let scores = [
        {name: 'Bob', math: 97, chinese: 89, english: 67},
        {name: 'Tom', math: 67, chinese: 52, english: 98},
        {name: 'Jerry', math: 72, chinese: 87, english: 89},
        {name: 'Ben', math: 92, chinese: 87, english: 59},
        {name: 'Chan', math: 47, chinese: 85, english: 92},
    ];

    let total_scores = [];
    for (stu of scores) {
        stu.total = stu.math + stu.chinese + stu.english;
        total_scores.push(stu);
    }



    for(let i = 0; i < total_scores.length - 1; i++) {
        for(let j = 0;  j < total_scores.length - 1 - i; j++) {
            if (total_scores[j].total < total_scores[j+1].total) {
                let t = total_scores[j];
                total_scores[j] = total_scores[j+1];
                total_scores[j+1] = t;
            }
        }
    }
    console.log(total_scores);



    new Vue({
        el: '#app',
        data: {
            scores: total_scores,
            rule: '',
            min: '',
            max: '',
        },
        methods: {
            clickAction(rule) {
                this.rule = rule;
            }
        }
        // filters: {
        //     f1(stu) {
        //         console.log(stu);
        //         return true
        //     }
        // }
    });


</script>
</html>
原文地址:https://www.cnblogs.com/luodaoqi/p/12061431.html