vue環(huán)形進(jìn)度條組件實(shí)例應(yīng)用
在做項(xiàng)目的時(shí)候,最好只使用一套組件庫,但是很多時(shí)候我們的組件庫里面沒有我們需要的組件,這個(gè)時(shí)候我們還是需要自己寫組件了,vux里面就沒有環(huán)形進(jìn)度條組件,所以需要自己寫一個(gè)。
查找資料后發(fā)現(xiàn)了一個(gè)很好的實(shí)現(xiàn)方式,通過svg來實(shí)現(xiàn),以前的時(shí)候?qū)W過一點(diǎn)svg但是沒有怎么深入了解過。。?,F(xiàn)在看來真是罪過,給出參考鏈接
https://segmentfault.com/a/1190000008149403
可以看出原作者使用了兩種方式,我們選擇了第二種,簡單,而且好擴(kuò)展。可以看到svg就想是canvas一樣進(jìn)行繪圖。原文已經(jīng)講得很詳細(xì)了,這里就附上自己寫的組件吧。伸手黨們也能愉快一點(diǎn)。
<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 () { // 所有進(jìn)度條的可配置項(xiàng) let baseOption = { radius: 20, strokeWidth: 5, outerColor: '#E6E6E6', innerColor: '#FFDE00', } Object.assign(baseOption, this.progressOption) // 中心位置自動(dòng)生成 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>
修改了原文中的一些不好的命名方式,并且讓我們的組件方便配置,可以自由一點(diǎn)。
以上就是本次知識點(diǎn)的全部內(nèi)容,感謝大家對腳本之家的支持。
相關(guān)文章
使用vue實(shí)現(xiàn)多規(guī)格選擇實(shí)例(SKU)
這篇文章主要介紹了使用vue實(shí)現(xiàn)多規(guī)格選擇實(shí)例(SKU),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08vue實(shí)戰(zhàn)中的一些實(shí)用小魔法匯總
這篇文章主要給大家介紹了關(guān)于vue實(shí)戰(zhàn)中一些實(shí)用小魔法的相關(guān)資料,這些技巧和竅門,可以幫助你成為更好的Vue開發(fā)人員,需要的朋友可以參考下2021-06-06在vue中使用eacharts創(chuàng)建graph關(guān)系圖方式
這篇文章主要介紹了在vue中使用eacharts創(chuàng)建graph關(guān)系圖方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09vue項(xiàng)目啟動(dòng)命令個(gè)人學(xué)習(xí)記錄
最近想要學(xué)習(xí)vue,正好看到資料,如何通過命令創(chuàng)建vue項(xiàng)目的方法,就留個(gè)筆記,下面這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目啟動(dòng)命令的相關(guān)資料,需要的朋友可以參考下2023-02-02