vue3中定時(shí)任務(wù)cron表達(dá)式組件的比較分析

背景
之前使用vue2開發(fā)項(xiàng)目時(shí),使用了cron組件,比較了兩種組件的使用效果。
現(xiàn)在需要把原有的vue2項(xiàng)目升級(jí)為vue3,需要對(duì)應(yīng)的cron組件。
方案一、vue3-cron-plus

具體實(shí)現(xiàn):
安裝插件
npm install vue3-cron-plus -S
vue文件使用實(shí)例:
<template>
<div>
<el-input class="elInput" v-model="cronValue" @click="openDialog" :clearable="true" placeholder="請(qǐng)輸入正確的cron表達(dá)式">
</el-input>
<el-dialog v-model="showCron">
<vue3CronPlus
@change="changeCron"
@close="closeDialog"
max-height="600px"
i18n="cn">
</vue3CronPlus>
</el-dialog>
</div>
</template>
<script>
import { vue3CronPlus } from 'vue3-cron-plus'
import 'vue3-cron-plus/dist/index.css' // 引入樣式
export default {
name : "DemoCompare",
components: { "vue3CronPlus":vue3CronPlus },
data () {
return{
cronValue:"",
showCron:"",
}
},
methods : {
openDialog () {
this.showCron = true;
},
closeDialog(){
this.showCron = false;
},
changeCron(cronValue){
if (typeof (cronValue) == "string") {
this.cronValue = cronValue;
}
}
}
}
</script>
<style scoped>
</style>
方案二、no-vue3-cron

具體實(shí)現(xiàn):
安裝插件
npm install no-vue3-cron -S
vue文件使用實(shí)例:
<template>
<div>
<el-input class="elInput" v-model="cronValue" @click="openDialog" :clearable="true" placeholder="請(qǐng)輸入正確的cron表達(dá)式">
</el-input>
<el-dialog v-model="showCron">
<noVue3Cron
:cron-value="cronValue"
@change="changeCron"
@close="closeDialog"
max-height="600px"
i18n="cn">
</noVue3Cron>
</el-dialog>
</div>
</template>
<script>
//局部引入
import { noVue3Cron } from 'no-vue3-cron'
import 'no-vue3-cron/lib/noVue3Cron.css' // 引入樣式
export default {
name : "DemoCompareShow",
components: { "noVue3Cron":noVue3Cron },
data () {
return{
cronValue:"",
showCron:"",
expression:"* * * * * * *"
}
},
methods : {
openDialog () {
this.showCron = true;
if (this.cronValue != "") {
this.expression = this.cronValue
}
},
closeDialog(){
this.showCron = false;
},
changeCron(cronValue){
if (typeof (cronValue) == "string") {
this.cronValue = cronValue;
}
}
}
}
</script>
<style scoped>
</style>
方案三、vue3-cron-plus-picker

具體實(shí)現(xiàn):
安裝插件
npm install vue3-cron-plus-picker -S
vue文件使用實(shí)例:
<template>
<div>
<el-input class="elInput" v-model="cronValue" @click="openDialog" :clearable="true" placeholder="請(qǐng)輸入正確的cron表達(dá)式">
</el-input>
<el-dialog v-model="showCron">
<Vue3CronPlusPicker @hide="closeDialog" @fill="fillValue" :expression="expression"/>
</el-dialog>
</div>
</template>
<script >
import 'vue3-cron-plus-picker/style.css'
import {Vue3CronPlusPicker} from 'vue3-cron-plus-picker'
export default {
name : "demoShow",
components : {"Vue3CronPlusPicker":Vue3CronPlusPicker,},
data () {
return{
cronValue:"",
showCron:"",
expression:"* * * * * * *"
}
},
methods : {
openDialog () {
this.showCron = true;
if (this.cronValue != ""){
this.expression = this.cronValue
}
},
closeDialog(){
this.showCron = false;
},
fillValue(cronValue){
this.cronValue = cronValue;
}
}
}
</script>
<style lang="scss" scoped>
</style>
對(duì)比
- 都可以從組件中獲取cron的表達(dá)式
vue3-cron-plus組件不能根據(jù)cron表達(dá)式回顯到組件vue3-cron-plus-picker組件可以看到將來(lái)執(zhí)行任務(wù)的具體時(shí)間,推薦使用
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
如何使用fetchEventSource實(shí)現(xiàn)sse流式請(qǐng)求
這篇文章主要介紹了如何使用fetchEventSource實(shí)現(xiàn)sse流式請(qǐng)求問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08
vue項(xiàng)目中使用eslint+prettier規(guī)范與檢查代碼的方法
這篇文章主要介紹了vue項(xiàng)目中使用eslint+prettier規(guī)范與檢查代碼的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01
基于Vue技術(shù)實(shí)現(xiàn)遞歸組件的方法
這篇文章主要為大家詳細(xì)介紹了基于Vue技術(shù)實(shí)現(xiàn)遞歸組件的方法 ,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
vue多次打包后出現(xiàn)瀏覽器緩存的問(wèn)題及解決
這篇文章主要介紹了vue多次打包后出現(xiàn)瀏覽器緩存的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
非Vuex實(shí)現(xiàn)的登錄狀態(tài)判斷封裝實(shí)例代碼
這篇文章主要給大家介紹了關(guān)于非Vuex實(shí)現(xiàn)的登錄狀態(tài)判斷封裝的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-02-02
Vue實(shí)現(xiàn)鼠標(biāo)懸浮切換圖片src
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)鼠標(biāo)懸浮切換圖片src,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
使用vuex解決刷新頁(yè)面state數(shù)據(jù)消失的問(wèn)題記錄
這篇文章主要介紹了使用vuex解決刷新頁(yè)面state數(shù)據(jù)消失的問(wèn)題記錄,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
vue二次封裝一個(gè)高頻可復(fù)用組件的全過(guò)程
在開發(fā)Vue項(xiàng)目我們一般使用第三方UI組件庫(kù)進(jìn)行開發(fā),但是這些組件提供的接口并不一定滿足我們的需求,這時(shí)我們可以通過(guò)對(duì)組件庫(kù)組件的二次封裝,來(lái)滿足我們特殊的需求,這篇文章主要給大家介紹了關(guān)于vue二次封裝一個(gè)高頻可復(fù)用組件的相關(guān)資料,需要的朋友可以參考下2022-10-10

