逻辑分析
- 首先在pinia中定义默认变量为fold为false,默认不折叠
import { defineStore } from 'pinia'
let useLayOutSettingStore = defineStore('SettingStore', {
state: () => {
return {
fold: false,
}
},
})
export default useLayOutSettingStore
<template>
<!-- 顶部左侧的图标 -->
<el-icon style="margin-right: 10px" @click="changeIcon">
<component :is="LayOutSettingStore.fold ? 'Fold' : 'Expand'"></component>
</el-icon>
。。。。。。。
</template>
<script setup lang="ts">
import useLayOutSettingStore from '@/store/modules/setting'
let LayOutSettingStore = useLayOutSettingStore()
const changeIcon = () => {
LayOutSettingStore.fold = !LayOutSettingStore.fold
}
</script>
。。。。。。
- 在以下组件中获取pinia中fold变量用来做判断
- 切换折叠图标样式
- 在左侧组件添加类名,控制该类名下的width为另一个变量
- 在menu组件控制collapse 是否折叠
- 控制右侧上面组件和内容区域组件的宽度和距离左侧的距离