feat: 添加@uni-ku/root依赖并配置vite插件

移除页面中的tabbar布局配置
在default.vue中暴露testUniLayoutExposedData
添加App.ku.vue作为根组件
更新pages.json移除tabbar布局配置
This commit is contained in:
feige996
2025-08-24 21:42:04 +08:00
parent 21cbb7970b
commit a108236784
9 changed files with 57 additions and 6 deletions

24
src/App.ku.vue Normal file
View File

@@ -0,0 +1,24 @@
<script setup lang="ts">
import { ref } from 'vue'
import FgTabbar from '@/tabbar/index.vue'
import { isPageTabbar } from './tabbar/store'
import { currRoute } from './utils'
const isCurrentPageTabbar = ref(true)
onShow(() => {
console.log('App.ku.vue onShow', currRoute())
const { path } = currRoute()
isCurrentPageTabbar.value = isPageTabbar(path)
})
const helloKuRoot = ref('Hello AppKuVue')
</script>
<template>
<view class="text-center">
{{ helloKuRoot }}这里可以配置全局的东西
</view>
<!-- 顶级 KuRootView -->
<KuRootView />
<FgTabbar v-if="isCurrentPageTabbar" />
</template>

View File

@@ -2,6 +2,11 @@
import { useThemeStore } from '@/store'
const themeStore = useThemeStore()
const testUniLayoutExposedData = ref('testUniLayoutExposedData')
defineExpose({
testUniLayoutExposedData,
})
</script>
<template>

View File

@@ -43,7 +43,6 @@
{
"path": "pages/index/index",
"type": "home",
"layout": "tabbar",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "首页"
@@ -52,7 +51,6 @@
{
"path": "pages/about/about",
"type": "page",
"layout": "tabbar",
"style": {
"navigationBarTitleText": "关于"
}
@@ -92,7 +90,6 @@
{
"path": "pages/me/me",
"type": "page",
"layout": "tabbar",
"style": {
"navigationBarTitleText": "我的"
}

View File

@@ -1,6 +1,5 @@
<route lang="jsonc" type="page">
{
"layout": "tabbar",
"style": {
"navigationBarTitleText": "关于"
}
@@ -49,6 +48,11 @@ onReady(() => {
console.log('onReady:', uniLayout.value) // onReady: Proxy(Object)
console.log('onReady:', uniLayout.value.testUniLayoutExposedData) // onReady: testUniLayoutExposedData
})
// 结论第一次通过onShow获取不到但是可以通过 onReady获取到后面就可以通过onShow获取到了
onShow(() => {
console.log('onShow:', uniLayout.value) // onReady: Proxy(Object)
console.log('onShow:', uniLayout.value?.testUniLayoutExposedData) // onReady: testUniLayoutExposedData
})
function gotoTabbar() {
uni.switchTab({

View File

@@ -1,7 +1,6 @@
<!-- 使用 type="home" 属性设置首页其他页面不需要设置默认为page -->
<route lang="jsonc" type="home">
{
"layout": "tabbar",
"style": {
// 'custom' 表示开启自定义导航栏,默认 'default'
"navigationStyle": "custom",

View File

@@ -1,6 +1,5 @@
<route lang="jsonc" type="page">
{
"layout": "tabbar",
"style": {
// 'custom' 表示开启自定义导航栏,默认 'default'
// "navigationStyle": "custom",