• 【Vue】V-if成立时,元素出现;不成立时,元素不显示。


    效果:V-if成立时,元素出现;不成立时,元素不显示。

    V-if成立时,元素出现
    在这里插入图片描述
    不成立时,元素不显示
    在这里插入图片描述

    代码

    关键点: < a v-if=“checkedNames.length > 0” :href=“‘/PPDASH/compare_by_different_employee2/’+this.checkedNames” >生成

    {% extends 'PPDASH/base.html' %}
    {% load static %}
    
    {% block body_block %}
    
    <!-- 调整color的js脚本开始 -->
    <script>
        window.onload = function(){
            paradom1 = document.getElementsByClassName("p1")
            console.log(paradom1)
            for (i = 0 ; i < paradom1.length; i++) {
                var para = document.getElementsByClassName("p1")[i];if (para.textContent <=35) {para.style.color = "red";}else if (para.textContent <65) {para.style.color = "orange";}else{para.style.color = "green";}
            }
        }
    </script>
    <!-- 调整color的js脚本介绍 -->
    
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    
    
    <div class="container-fluid" id="app">
        <p class="my-3">
            查询结果如下&nbsp;&nbsp;
            <a href="/PPDASH/compare_by_different_employee/{{ employee_list }}/" >自动生成对比图(前20名)</a>
            <span>勾选工号生成对比图</span>
            <span>[[ checkedNames ]]</span>
            <a v-if="checkedNames.length > 0" :href="'/PPDASH/compare_by_different_employee2/'+this.checkedNames" >生成</a>
        </p>
    
        <table class="table table-striped table-bordered" >
            <thead>
                <tr style="color:White;background-color:#3366FF;font-family:微軟正黑體,Tahoma,Arial,微軟雅黑體;font-size:10px;">
                    <th scope="col">勾选</th>
                    <th scope="col">工號</th>
                    <th scope="col" style="width:80px;">姓名</th>
                    <th scope="col">部門</th>
                    <th scope="col">Level</th>
                    <th scope="col">Function</th>
                    <th scope="col">批次</th>
                    <th scope="col">接纳反馈</th>
                    <th scope="col">学习敏锐度</th>
                    <th scope="col">结果导向</th>
                    <th scope="col">全局思维</th>
                    <th scope="col">适应力</th>
                    <th scope="col">成就他人</th>
                    <th scope="col">领导意愿</th>
                    <th scope="col">平衡人际与任务</th>
                    <th scope="col">辅导*</th>
                    <th scope="col">授权委责*</th>
                    <th scope="col">建立成功团队*</th>
                    <th scope="col">管理人际关系*</th>
                    <th scope="col">影响力*</th>
                    <th scope="col">建立伙伴关系*</th>
                    <th scope="col">计划与组织*</th>
                </tr>
            </thead>
    
        
            {% for employee in pageInfo.object_list %}
            <tr valign="middle" style="color:Black;border-color:#E0E0E0;font-size:10px;">
                <td><input type="checkbox" id="{{ employee.eid }}" value="{{ employee.eid }}" v-model="checkedNames" /></td>
                <td><a href="/PPDASH/search_results/{{ employee.eid }}/">{{ employee.eid }}</a></td>
                <td>{{ employee.name }}</td>
                <td>{{ employee.dept_code }}</td>
                <td>{{ employee.level }}</td>
                <td>{{ employee.function }}</td>
                <td>{{ employee.batch }}</td>
                <td class="p1">{{ employee.score_jieshoufankui }}</td>
                <td class="p1">{{ employee.score_xueximinruidu }}</td>
                <td class="p1">{{ employee.score_jieguodaoxiang }}</td>
                <td class="p1">{{ employee.score_quanjusiwei }}</td>
                <td class="p1">{{ employee.score_shiyingli }}</td>
                <td class="p1">{{ employee.score_chengjiutaren }}</td>
                <td class="p1">{{ employee.score_lingdaoyiyuan }}</td>
                <td class="p1">{{ employee.score_pinghengrenjiyurenwu }}</td>
                <td class="p1">{{ employee.score_fudao }}</td>
                <td class="p1">{{ employee.score_shouquanweize }}</td>
                <td class="p1">{{ employee.score_jianlichenggongtuandui }}</td>
                <td class="p1">{{ employee.score_guanlirenjiguanxi }}</td>
                <td class="p1">{{ employee.score_yingxiangli }}</td>
                <td class="p1">{{ employee.score_jianlihuobanguanxi }}</td>
                <td class="p1">{{ employee.score_jihuayuzuzhi }}</td>
            </tr>
            {% endfor %}
    
        </table>
    
    
        <!--分页功能-->
        <div class="pagelist">
            {% if pageInfo.has_previous %}
                <a href="{% url 'search_results' pageInfo.previous_page_number %}">上一页</a>
            {% endif %}
                        
            {% if pageInfo.object_list %}
                {% for page in pageInfo.paginator.page_range %}
                    {% if pageInfo.number == page %}
                        <a href="javascript:;" class="curPage">本页</a>
                    {% else %}
                        <a href="{% url 'search_results' page %}">{{ page }}</a>
                    {% endif %}
                {% endfor %}
            {% endif %}
                        
            {% if pageInfo.has_next %}
                <a href="{% url 'search_results' pageInfo.next_page_number %}">下一页</a>
            {% endif %}
        </div>
    
    </div>
    
    
    
    
    
    
    <script type="text/javascript">
        // 获取变量值
        // var plantid_list_js = JSON.parse('{{ plantid_list|safe }}');
        // var function_list_js = JSON.parse('{{ function_list|safe }}');
        // var name_list_js = JSON.parse('{{ name_list|safe }}');
    
    
        var app = new Vue({
            delimiters:['[[', ']]'],
            el: '#app',
            data() {
                return {
                    checkedNames: [],
                    // message_plantid: '',
                    // message_dept: '',
                    // message_function: '',
                    // message_eid: '',
                    // message_name: '',
                    // // options: ['P1','P3','P6','其他'],
                    // plantid_options: plantid_list_js,
                    // function_options: function_list_js,
                    // name_options: name_list_js,
                }
                },
            methods:{
                // add:function () {
                //   this.arrlist.push()
                // }
            },
            computed: {
                // // 计算属性的 getter
                // checkedNames_trim: function () {
                // // `this` 指向 vm 实例
                // return this.checkedNames
                // }
            }
        });
    
    </script>
    
    
    
    
    {% endblock %}
    
    
    
    <!-- 不用页脚 -->
    {% block footer_block %}
    
    {% endblock %}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
  • 相关阅读:
    【译】如何使库与本机 AOT 兼容(二)
    NOI2022游记
    两年经验前端带你重学前端框架必会的ajax+node.js+webpack+git等技术 Day3
    Linux虚拟网络设备—Veth Pair
    grafana接入OpenTSDB设置大盘语法
    Python:每日一题之四平方和
    Google Earth Engine(GEE)——不同时期的光谱信息差异
    做一个小记录
    软件测试7大误区
    spring mvc:请求执行流程(一)之获取Handler
  • 原文地址:https://blog.csdn.net/m0_46629123/article/details/125510004