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

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

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

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

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

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

Loading…
Cancel
Save