美文网首页
vue的v-show指令实现2种样式切换效果

vue的v-show指令实现2种样式切换效果

作者: 似朝朝我心 | 来源:发表于2021-12-17 13:57 被阅读0次

效果:


html

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <link rel="stylesheet" type="text/css" href="./style.css"/>
</head>
<body>
    <div id="container">
        <button type="button" class="button" @click="switchTab('default')">列表显示</button>
        <button type="button" class="button" style="margin-left: 10px;" @click="switchTab('another')">大图标显示</button>
        <div style="clear: both;border-bottom: 1px solid #000000;"></div>
        <!-- 列表显示 -->
        <div id="tabs1" v-show="hideOrShow1">
            <table border="" cellspacing="" cellpadding="">
                <tr>
                    <th>名称</th>
                    <th>修改日期</th>
                    <th>类型</th>
                    <th>大小</th>
                </tr>
                <tr v-for="(item,index) in dataList" :key="index">
                    <td style="width: 300px;">
                        <img style="width: 20px;height: 20px;" :src="item.imgUrl" >
                        <a href="">{{item.fileName}}</a>
                    </td>
                    <td>{{item.updateTime}}</td>
                    <td>{{item.type}}</td>
                    <td>{{item.size}}</td>
                </tr>
            </table>
        </div>
        <!-- 列表显示 -->
        <!-- 大图标显示 -->
        <div id="tabs2" v-show="hideOrShow2" style="margin-top: 10px;">
            <div id="box" v-for="(item,index) in dataList" :key="index">
                <img :src="item.imgUrl" >
                <p>{{item.fileName}}</p>
            </div>
        </div>
        <!-- 大图标显示 -->
    </div>
    <script type="text/javascript">
        const container = new Vue({
            el: "#container",
            data () {
                return {
                    hideOrShow1: true,
                    hideOrShow2: false,
                    dataList: [
                        {
                            imgUrl: "./images/1.png",
                            fileName: "MyDeploy.sh",
                            updateTime: "2021/12/17 8:38",
                            type: "SH 文件",
                            size: "1 KB"
                        },
                        {   
                            imgUrl: "./images/1.png",
                            fileName: "MyCheckData.sh",
                            updateTime: "2021/12/17 8:39",
                            type: "SH 文件",
                            size: "21 KB"
                        },
                        {
                            imgUrl: "./images/1.png",
                            fileName: "MobaXterm_Portable_v20.0",
                            updateTime: "2021/12/17 9:39",
                            type: "文件夹",
                            size: "764 KB"
                        },
                        {
                            imgUrl: "./images/1.png",
                            fileName: "Qt5Concurrent.dll",
                            updateTime: "2020/09/17 19:39",
                            type: "应用程序扩展",
                            size: "33 KB"
                        },
                        {
                            imgUrl: "./images/1.png",
                            fileName: "MyDeploy.sh",
                            updateTime: "2021/12/17 8:38",
                            type: "SH 文件",
                            size: "1 KB"
                        },
                        {   
                            imgUrl: "./images/1.png",
                            fileName: "MyCheckData.sh",
                            updateTime: "2021/12/17 8:39",
                            type: "SH 文件",
                            size: "21 KB"
                        },
                        {
                            imgUrl: "./images/1.png",
                            fileName: "MobaXterm_Portable_v20.0",
                            updateTime: "2021/12/17 9:39",
                            type: "文件夹",
                            size: "764 KB"
                        },
                        {
                            imgUrl: "./images/1.png",
                            fileName: "Qt5Concurrent.dll",
                            updateTime: "2020/09/17 19:39",
                            type: "应用程序扩展",
                            size: "33 KB"
                        }
                    ]
                }
            },
            methods: {
                switchTab (value) {
                    switch (value) {
                        case 'default':
                        this.hideOrShow1 = true
                        this.hideOrShow2 = false
                        break;
                        case 'another':
                        this.hideOrShow1 = false
                        this.hideOrShow2 = true
                        break;
                    }
                }
            }
        })
    </script>
</body>
</html>

css

*{
    margin: 0;
    padding: 0;
}
.button {
    background-color: #4CAF50; /* Green */
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    cursor: pointer;
    float: left;
    border-radius: 4px;
    margin: 10px;
}
.button:hover {
    background-color: #3e8e41;
}

/* 列表显示样式 */
#tabs1 table,th,tr,td {
    border: none;
    text-align: left;
}
#tabs1 td {
    width: 200px;
}

/* 大图标显示样式 */
#tabs2 {
    width: 700px;
}
#tabs2 img {
    height: 150px;
    width: 150px;
}
#tabs2 {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
}
#tabs2 #box {
    width: 200px;
}

相关文章

  • vue的v-show指令实现2种样式切换效果

    效果: html css

  • vue.js实战---添加/删除数据

    vue.js简单实现的页面添加数据,删除数据的效果,效果如下图 代码: css样式: 运用点: v-show : ...

  • Vue指令之v-show

    Vue指令之v-show v-show 指令根据表达式的真假来显示元素和隐藏,是响应式的v-show 指令通过改变...

  • 2020-04-09vue

    Vue基本指令 改变样式 v-for v-if与v-show 过滤器 生命周期 动画过渡 定义组件 组件中的dat...

  • tab页签切换组件

    2019年12月27日 一.样式1 1.通用固定tab切换样式 2.顶部切换效果实现 二.样式1 1.效果: 2....

  • Vue.js实现“增、删”实例

    刚发完Vue.js(2)----常用指令,做个实例巩固一下,来实现对数组的增加和删除的效果。 样式就省略不说,感兴...

  • 8 个非常实用的 Vue 自定义指令

    在 Vue,除了核心功能默认内置的指令 ( v-model 和 v-show ),Vue 也允许注册 自定义指令...

  • Vue 自定义指令 案列

    在 Vue,除了核心功能默认内置的指令 ( v-model 和 v-show ),Vue 也允许注册 自定义指令。...

  • vue知识集锦(三)

    自定义指令 除了核心功能默认内置的指令 (v-model和v-show),Vue 也允许注册自定义指令。尽管Vue...

  • Vue自定义指令

      除了默认设置的核心指令( v-model 和 v-show ),Vue 也允许注册自定义指令。在Vue里,代码...

网友评论

      本文标题:vue的v-show指令实现2种样式切换效果

      本文链接:https://www.haomeiwen.com/subject/atjifrtx.html