效果:
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;
}