在MenuLogo.vue中解决当菜单栏收缩时,标题文字不收缩的问题

添加show变量,通过布尔值控制文字显示
通过watch监听show变量值的变化,实现延时函数,美化标题收缩效果
pull/16/head
riverflow 2 months ago
parent 47c6c8c86f
commit c03731ff32

@ -107,7 +107,7 @@
//
const collapse = computed(()=>{
return store.getcollapse
return store.getCollapse
})
</script>

@ -1,17 +1,42 @@
<template>
<div class="logo">
<img :src="MenuLogo">
<span class="logo-title">{{ title }}</span>
<span v-if="show" class="logo-title">{{ title }}</span>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { ref,watch } from 'vue'
const MenuLogo = ref(
"https://wpimg.wallstcn.com/69a1c46c-eb1c-4b46-8bd4-e9e686ef5251.png"
);
// storeuseCollapseStorecollapse&
import { useCollapseStore } from '@/store/collapse'
// store
const store = useCollapseStore()
//
const title = ref('校园点餐系统')
// &
const show = ref(true)
// watch
watch(
()=> store.getCollapse,
(collapsed: boolean) => {
if (!collapsed){
setTimeout(() =>{
show.value = !collapsed
},300)
}else{
show.value = !collapsed
}
}
)
</script>
<style scoped lang="scss">

@ -27,12 +27,12 @@
//
const status = computed(()=>{
return store.getcollapse
return store.getCollapse
})
//
const iconClick = ()=>{
// collapse
store.collapse = (!store.collapse)
}

@ -10,7 +10,7 @@ export const useCollapseStore = defineStore('collapseStore', {
// getter
getters:{
// 数据放在state里面需要传递state
getcollapse(state){
getCollapse(state){
return state.collapse
}
},
@ -18,7 +18,7 @@ export const useCollapseStore = defineStore('collapseStore', {
// action
actions:{
// 设置state里面的数据
setcollapse(collapse:boolean){
setCollapse(collapse:boolean){
this.collapse = collapse
}
}

Loading…
Cancel
Save