vue環(huán)形進(jìn)度條組件實例應(yīng)用
在做項目的時候,最好只使用一套組件庫,但是很多時候我們的組件庫里面沒有我們需要的組件,這個時候我們還是需要自己寫組件了,vux里面就沒有環(huán)形進(jìn)度條組件,所以需要自己寫一個。
查找資料后發(fā)現(xiàn)了一個很好的實現(xiàn)方式,通過svg來實現(xiàn),以前的時候?qū)W過一點svg但是沒有怎么深入了解過。?!,F(xiàn)在看來真是罪過,給出參考鏈接
https://segmentfault.com/a/1190000008149403
可以看出原作者使用了兩種方式,我們選擇了第二種,簡單,而且好擴(kuò)展??梢钥吹絪vg就想是canvas一樣進(jìn)行繪圖。原文已經(jīng)講得很詳細(xì)了,這里就附上自己寫的組件吧。伸手黨們也能愉快一點。
<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)度條的可配置項
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中v-cloak解決刷新或者加載出現(xiàn)閃爍問題(顯示變量)
這篇文章主要介紹了vue中v-cloak解決刷新或者加載出現(xiàn)閃爍問題(顯示變量) ,需要的朋友可以參考下2018-04-04
vue使用video插件vue-video-player詳解
這篇文章主要為大家詳細(xì)介紹了vue使用video插件vue-video-player,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-10-10
淺談webpack SplitChunksPlugin實用指南
這篇文章主要介紹了淺談webpack SplitChunksPlugin實用指南,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09
解決ant design vue 表格a-table二次封裝,slots渲染的問題
這篇文章主要介紹了解決ant design vue 表格a-table二次封裝,slots渲染的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10

