由於對於vue了解不夠深入,導致今天寫這個組件浪費了很多時間。后來一個大神同事給我指點了一下。
想做成如圖所示的樣式的步驟條,使用vue elementui的steps組件做。
最簡單的在組件中插入代碼實現樣式的方法時行不通的
<div style="height: 300px;"> <el-steps direction="vertical" :active="1"> <el-step title="步驟 1"> <div>001002003 </div> </el-step> <el-step title="步驟 2"></el-step> <el-step title="步驟 3" description="這是一段很長很長很長的描述性文字"></el-step> </el-steps> </div>
所以想了一種辦法,使用左右兩個div實現。不過步驟條的長度,和步驟條中顯示的具體內容的位置也非常不好判斷。
<div class="approvalProcess" style="backgroung-color:background-color:#DFEBFF;" > <div class='approvalProcess_left'> <el-steps :active="active" finish-status="success" direction="vertical"> <el-step :title="item.label" v-for="item in approvalProcessProject" :id="item.id"> </el-step> </el-steps> <el-button style="margin-top: 12px;" @click="next">下一步</el-button> </div> <div class='approvalProcess_right'> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="processing_content"> <tr> <td > <div class="processing_content_detail" style="float:left;width:70%"><span class="title_tjname">申請人 圓領 提交了割接方案</span></div> <div class="processing_content_detail" style="float:right;"><span class="title_tjname">昨天12::24</span> </div> </td> </tr> <tr> <td> <div class="processing_content_detail" style="float:left;width:70%"> <div style="float:left;width: 2px;height: 20px; background:#C7D4E9;margin-left:10px;margin-right:10px"></div> <span class="title_tjname" style="color:#919FB8">同意,建議通過 www.dianjilingqu.com</span></div> </td> </tr> </table> </div>
后來嘗試了使用vue的插槽,建一個template的插槽。名字用description 就能進去了。我需要惡補下插槽的相關知識。
<div class="stepComponent" > <div class="stepsTitle"> <div style="float:left;width:2px;height:20px; background:#219AFF;"></div> 審批流程及意見 www.dianjilingqu.com </div> <div class="approvalProcess" > <el-steps :active="active" finish-status="success" direction="vertical" > <el-step :title="item.label" v-for="item in approvalProcessProject" :id="item.id"> <template slot="description" > <div class="step-row" v-for="item in approvalProcessProject"> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="processing_content"> <tr> <td style="color:#98A6BE"> <div class="processing_content_detail" style="float:left;width:70%"><span >申請人 <span style="color:#219AFF">圓領{{}}</span> 提交了割接方案</span></div> <div class="processing_content_detail" style="float:right;"><span ><i class="el-icon-time"></i> 昨天12:24</span> </div> </td> </tr> <tr> <td> <div class="processing_content_detail" style="float:left;width:70%"> <div style="float:left;width: 2px;height: 20px; background:#C7D4E9;margin-left:10px;margin-right:10px"></div> <span style="color:#919FB8">同意,建議通過</span></div> </td> </tr> </table> </div> </template> </el-step> </el-steps> <el-button style="margin-top: 12px;" @click="next">下一步</el-button> </div> </div> </template> <script> export default { components: { }, props: ['data', 'defaultActive'], data() { return { active: 0, approvalProcessProject:[ {id:'0',label: "方案制定"}, { id:'1',label: "割接方案會審"}, { id:'2',label: "割接審批"}, { id:'3',label: "審批成功"}, ], }; }, watch: { }, mounted() { }, computed: { }, methods: { next() { if (this.active++ > 2) this.active = 0; }, } }; </script> <style scoped> .stepComponent{ background-color:#DFEBFF; width: 100%-20px; padding: 10px 10px 10px 10px; margin: 10px 10px 10px 10px; } .stepsTitle{ margin: 10px 0px 10px 10px ; } .approvalProcess{ color: #9EADC4; font-size: 14px; /* width: 100%; */ background:#DFEBFF; margin-left:20px; margin-right:0px; margin-top:10px; } .processing_content{ background-color: #D9E5F9; } .processing_content_detail{ margin-left: 10px; margin-top: 3.5px; margin-bottom: 3.5px; width:150px; display:inline-block; } .step-row{ min-width:500px; margin-bottom:12px; margin-top:12px; } </style>
下面是我寫好的樣式
基本可以實現所需樣式。
有同學問:如何把圖標換成圖片?
是想要這樣效果嗎?代碼載下面
<el-steps :active="1"> <el-step title="步驟 1 www.dianjilingqu.com"> <template slot="icon" > <img src="http://img4.imgtn.bdimg.com/it/u=2480604110,4008147240&fm=26&gp=0.jpg" style="height:25x;width:25px;"> </template> </el-step> <el-step title="步驟 2" icon="el-icon-upload"> <template slot="icon" > <img src="http://img.zcool.cn/community/01bc1c5694b3e932f87574bef9bc29.png" style="height:25x;width:25px;"> </template> </el-step> </el-step> <el-step title="步驟 3" icon="el-icon-picture"></el-step> </el-steps> </div>