生命周期优化

This commit is contained in:
xiaozzzi 2023-11-28 19:44:20 +08:00
parent 25476d417f
commit 329dd1a909
3 changed files with 24 additions and 16 deletions

View File

@ -85,17 +85,20 @@
</template>
<script setup lang="ts">
import { ref, onMounted, onActivated } from 'vue'
import { ref } from 'vue'
import { useUserStore } from '@renderer/stores/user'
import { getAll, refreshApi } from '@renderer/api/weather'
import { useLifecycle } from '@renderer/scripts/lifecycle'
onMounted(() => {
refreshWeatherTask()
})
onActivated(() => {
getWeather()
})
useLifecycle(
() => {
refreshWeatherTask()
getWeather()
},
() => {
getWeather()
}
)
const userStore = useUserStore()

View File

@ -22,8 +22,20 @@
<script setup lang="ts">
import { articleWordsApi, pictureStatApi } from '@renderer/api/blossom'
import { onActivated, ref } from 'vue'
import { ref } from 'vue'
import { formatFileSize, formartNumber } from '@renderer/assets/utils/util'
import { useLifecycle } from '@renderer/scripts/lifecycle'
useLifecycle(
() => {
getArticleWords()
getPictureStat()
},
() => {
getArticleWords()
getPictureStat()
}
)
let article = ref({ articleCount: 0, articleWords: 0 })
let picture = ref({ pictureCount: 0, pictureSize: 0 })
@ -39,11 +51,6 @@ const getPictureStat = () => {
picture.value = resp.data
})
}
onActivated(() => {
getArticleWords()
getPictureStat()
})
</script>
<style scoped lang="scss">

View File

@ -33,7 +33,6 @@ const props = defineProps({
}
})
// -------------------- ref
const rqLoading = ref<boolean>(true)
const ChartLineMetricRef = ref<any>(null)
let chartLineMetric: any
@ -46,7 +45,6 @@ let chartData = {
maxVisual: 0
}
// -------------------- methods
/**
* 查询指标数据
* @param resource 资源