vue環(huán)形進度條組件實例應(yīng)用
在做項目的時候,最好只使用一套組件庫,但是很多時候我們的組件庫里面沒有我們需要的組件,這個時候我們還是需要自己寫組件了,vux里面就沒有環(huán)形進度條組件,所以需要自己寫一個。
查找資料后發(fā)現(xiàn)了一個很好的實現(xiàn)方式,通過svg來實現(xiàn),以前的時候?qū)W過一點svg但是沒有怎么深入了解過。?!,F(xiàn)在看來真是罪過,給出參考鏈接
https://segmentfault.com/a/1190000008149403
可以看出原作者使用了兩種方式,我們選擇了第二種,簡單,而且好擴展??梢钥吹絪vg就想是canvas一樣進行繪圖。原文已經(jīng)講得很詳細了,這里就附上自己寫的組件吧。伸手黨們也能愉快一點。
<template> <svg :height="option.size" :width="option.size" x-mlns="http://www.w3.org/200/svg"> <circle :r="option.radius" :cx="option.cx" :cy="option.cy" :stroke="option.outerColor" :stroke-width="option.strokeWidth" fill="none" stroke-linecap="round"/> <circle id="progressRound" :stroke-dasharray="completenessHandle" :r="option.radius" :cx="option.cx" :cy="option.cy" :stroke-width="option.strokeWidth" :stroke="option.innerColor" fill="none" class="progressRound" /> </svg> </template> <script> export default { name: 'CommonLoopProgress', props: { completeness: { type: Number, required: true, }, progressOption: { type: Object, default: () => {}, }, }, data () { return { } }, computed: { completenessHandle () { let circleLength = Math.floor(2 * Math.PI * this.option.radius) let completenessLength = this.completeness * circleLength return `${completenessLength},100000000` }, option () { // 所有進度條的可配置項 let baseOption = { radius: 20, strokeWidth: 5, outerColor: '#E6E6E6', innerColor: '#FFDE00', } Object.assign(baseOption, this.progressOption) // 中心位置自動生成 baseOption.cy = baseOption.cx = baseOption.radius + baseOption.strokeWidth baseOption.size = (baseOption.radius + baseOption.strokeWidth) * 2 return baseOption }, }, } </script> <style scoped lang='stylus'> @import '~stylus/_variables.styl'; @import '~stylus/_mixins.styl'; .progressRound { transform-origin: center; transform: rotate(-90deg); transition: stroke-dasharray 0.3s ease-in; } </style>
修改了原文中的一些不好的命名方式,并且讓我們的組件方便配置,可以自由一點。
以上就是本次知識點的全部內(nèi)容,感謝大家對腳本之家的支持。
相關(guān)文章
使用vue實現(xiàn)多規(guī)格選擇實例(SKU)
這篇文章主要介紹了使用vue實現(xiàn)多規(guī)格選擇實例(SKU),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08在vue中使用eacharts創(chuàng)建graph關(guān)系圖方式
這篇文章主要介紹了在vue中使用eacharts創(chuàng)建graph關(guān)系圖方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09