Element: 卡片

来自CloudWiki
跳转至: 导航搜索

将信息聚合在卡片容器中展示。

基础用法

包含标题,内容和操作。

Card 组件包括header和body部分,header部分需要有显式具名 slot 分发,同时也是可选的。

效果图

Vue2022071901.png

代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>VUE第一个案例-helloWorld</title>
	<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>

	<!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style type="text/css">
.title{
	font-size:20px;
	line-height:50px;
}

             .text {
               font-size: 14px;
             }
           
             .item {
               margin-bottom: 18px;
			   
             }
           
             .clearfix:before,
             .clearfix:after {
               display: table;
               content: "";
             }
             .clearfix:after {
               clear: both
             }
           
             .box-card {
               width: 100%;
			   height:300px;
             }

</style>

</head>

<body>
    <div id="app">
		<el-row :gutter="12">
		  <el-col :span="8" >
           <el-card class="box-card" style="height: 300px">
             <div slot="header" class="clearfix">
               <span>卡片名称</span>
               <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button>
             </div>
             <div v-for="o in 8" :key="o" class="text item">
               {{'列表内容 ' + o }}
             </div>
           </el-card>
		   </el-col>
		   <el-col :span="8" >
		    <el-card class="box-card" style="height: 300px">
		      <div slot="header" class="clearfix">
		        <span>卡片名称</span>
		        <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button>
		      </div>
		      <div v-for="o in 8" :key="o" class="text item">
		        {{'列表内容 ' + o }}
		      </div>
		    </el-card>
		    </el-col>
			<el-col :span="8" >
			 <el-card class="box-card" style="height: 300px">
			   <div slot="header" class="clearfix">
			     <span>卡片名称</span>
			     <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button>
			   </div>
			   <div v-for="o in 8" :key="o" class="text item">
			     {{'列表内容 ' + o }}
			   </div>
			 </el-card>
			 </el-col>
		</el-row>
           


	  
	  </div>
	


 
<script>
        new Vue({
            el: '#app',
           
			data() {
			  return {
			   }
			},
			methods: {

			}
        })
		

    </script>
</body>
</html>

简单卡片

效果图

Vue2022071902.png

代码

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>VUE第一个案例-helloWorld</title>
		<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>

		<!-- 引入样式 -->
		<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
		<!-- 引入组件库 -->
		<script src="https://unpkg.com/element-ui/lib/index.js"></script>
		<style type="text/css">
			.text {
				font-size: 14px;
			}

			.item {
				padding: 18px 0;
			}

			.box-card {
				width: 100%;
			}
			
		</style>

	</head>

	<body>
		<div id="app">
			<el-row :gutter="12">
				<el-col :span="8">
					<el-card class="box-card">
						<div v-for="o in 4" :key="o" class="text item">
							{{'列表内容 ' + o }}
						</div>
					</el-card>

			     </el-col>
				 <el-col :span="8">
				 	<el-card class="box-card">
				 		<div v-for="o in 4" :key="o" class="text item">
				 			{{'列表内容 ' + o }}
				 		</div>
				 	</el-card>
				 
				  </el-col>
				  <el-col :span="8">
				  	<el-card class="box-card">
				  		<div v-for="o in 4" :key="o" class="text item">
				  			{{'列表内容 ' + o }}
				  		</div>
				  	</el-card>
				  
				   </el-col>
			</el-row>




		</div>




		<script>
			new Vue({
				el: '#app',

				data() {
					return {}
				},
				methods: {

				}
			})
		</script>
	</body>
</html>

带图片

可配置定义更丰富的内容展示。

配置body-style属性来自定义body部分的style,我们还使用了布局组件。

效果图

Vue2022071903.png

代码

 
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>VUE第一个案例-helloWorld</title>
		<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>

		<!-- 引入样式 -->
		<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
		<!-- 引入组件库 -->
		<script src="https://unpkg.com/element-ui/lib/index.js"></script>
		<style type="text/css">
			.time {
				font-size: 13px;
				color: #999;
			}

			.bottom {
				margin-top: 13px;
				line-height: 12px;
			}

			.button {
				padding: 0;
				float: right;
			}

			.image {
				width: 100%;
				display: block;
			}

			.clearfix:before,
			.clearfix:after {
				display: table;
				content: "";
			}

			.clearfix:after {
				clear: both
			}
		</style>

	</head>

	<body>
		<div id="app">


			<el-row>
				<el-col :span="6" v-for="(o, index) in 3" :key="o" :offset="index > 0 ? 3 : 0">
					<el-card :body-style="{ padding: '0px' }">
						<img src="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png"
							class="image">
						<div style="padding: 14px;">
							<span>好吃的汉堡</span>
							<div class="bottom clearfix">
								<time class="time">{{ currentDate }}</time>
								<el-button type="text" class="button">操作按钮</el-button>
							</div>
						</div>
			  </el-card>
				</el-col>
			</el-row>




		</div>




		<script>
			new Vue({
				el: '#app',

				data() {
					return {
						currentDate: new Date()
					};
				},
				methods: {

				}
			})
		</script>
	</body>
</html>