layout/ 目录下文件用 script setup 语法糖重写

This commit is contained in:
hooray 2021-09-08 09:15:52 +08:00
parent 516fcba5ed
commit a88ebdfa89
2 changed files with 42 additions and 57 deletions

View File

@ -66,6 +66,7 @@ module.exports = {
'after': true,
'before': false
}],
'object-curly-spacing': [2, 'always'],
// ES6
'arrow-parens': [2, 'as-needed'],
'arrow-spacing': [2, {

View File

@ -30,7 +30,7 @@
</div>
</template>
<script>
<script setup>
import Header from './components/Header/index.vue'
import MainSidebar from './components/MainSidebar/index.vue'
import SubSidebar from './components/SubSidebar/index.vue'
@ -39,64 +39,48 @@ import Search from './components/Search/index.vue'
import ThemeSetting from './components/ThemeSetting/index.vue'
import BuyIt from './components/BuyIt/index.vue'
export default {
name: 'Layout',
components: {
Header,
MainSidebar,
SubSidebar,
Topbar,
Search,
ThemeSetting,
BuyIt
},
provide() {
return {
reload: this.reload,
switchMenu: this.switchMenu
import { provide, computed, watch, getCurrentInstance, onMounted } from 'vue'
import { useStore } from 'vuex'
import { useRoute, useRouter } from 'vue-router'
const { proxy } = getCurrentInstance()
const store = useStore()
const route = useRoute(), router = useRouter()
const showCopyright = computed(() => {
return typeof route.meta.copyright !== 'undefined' ? route.meta.copyright : store.state.settings.showCopyright
})
watch(() => store.state.settings.sidebarCollapse, val => {
if (store.state.settings.mode === 'mobile') {
if (!val) {
document.querySelector('body').classList.add('hidden')
} else {
document.querySelector('body').classList.remove('hidden')
}
},
data() {
return {
routePath: ''
}
},
computed: {
showCopyright() {
return typeof this.$route.meta.copyright !== 'undefined' ? this.$route.meta.copyright : this.$store.state.settings.showCopyright
}
},
watch: {
'$store.state.settings.sidebarCollapse'(val) {
if (this.$store.state.settings.mode === 'mobile') {
if (!val) {
document.querySelector('body').classList.add('hidden')
} else {
document.querySelector('body').classList.remove('hidden')
}
}
}
},
mounted() {
this.$hotkeys('f5', e => {
if (this.$store.state.settings.enablePageReload) {
e.preventDefault()
this.reload()
}
})
},
methods: {
reload() {
this.$router.push({
name: 'reload'
})
},
switchMenu(index) {
this.$store.commit('menu/switchHeaderActived', index)
if (this.$store.state.settings.switchSidebarAndPageJump) {
this.$router.push(this.$store.getters['menu/sidebarRoutes'][0].path)
}
}
})
onMounted(() => {
proxy.$hotkeys('f5', e => {
if (store.state.settings.enablePageReload) {
e.preventDefault()
reload()
}
})
})
provide('reload', reload)
function reload() {
router.push({
name: 'reload'
})
}
provide('switchMenu', switchMenu)
function switchMenu(index) {
store.commit('menu/switchHeaderActived', index)
if (store.state.settings.switchSidebarAndPageJump) {
router.push(store.getters['menu/sidebarRoutes'][0].path)
}
}
</script>