diff --git a/package.json b/package.json
index 00d881d..28a8201 100644
--- a/package.json
+++ b/package.json
@@ -144,6 +144,7 @@
"@uni-helper/vite-plugin-uni-pages": "0.3.0",
"@uni-helper/vite-plugin-uni-platform": "0.0.5",
"@uni-ku/bundle-optimizer": "^1.3.3",
+ "@uni-ku/root": "^1.3.2",
"@unocss/eslint-plugin": "^66.2.3",
"@vue/runtime-core": "3.4.21",
"@vue/tsconfig": "^0.1.3",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index b73b6c1..f3655be 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -167,6 +167,9 @@ importers:
'@uni-ku/bundle-optimizer':
specifier: ^1.3.3
version: 1.3.8(postcss@8.5.6)(rollup@4.46.2)(vite@5.2.8(@types/node@20.19.9)(sass@1.77.8)(terser@5.43.1))(vue@3.4.21(typescript@5.8.3))
+ '@uni-ku/root':
+ specifier: ^1.3.2
+ version: 1.3.2(vite@5.2.8(@types/node@20.19.9)(sass@1.77.8)(terser@5.43.1))
'@unocss/eslint-plugin':
specifier: ^66.2.3
version: 66.4.0(eslint@9.32.0(jiti@2.5.1))(typescript@5.8.3)
@@ -1155,11 +1158,13 @@ packages:
'@esbuild/darwin-arm64@0.20.2':
resolution: {integrity: sha512-4J6IRT+10J3aJH3l1yzEg9y3wkTDgDk7TSDFX+wKFiWjqWp/iCfLIYzGyasx9l0SAFPT1HwSCR+0w/h1ES/MjA==}
engines: {node: '>=12'}
+ cpu: [arm64]
os: [darwin]
'@esbuild/darwin-x64@0.20.2':
resolution: {integrity: sha512-tBcXp9KNphnNH0dfhv8KYkZhjc+H3XBkF5DKtswJblV7KlT9EI2+jeA8DgBjp908WEuYll6pF+UStUCfEpdysA==}
engines: {node: '>=12'}
+ cpu: [x64]
os: [darwin]
'@esbuild/freebsd-arm64@0.20.2':
@@ -1784,6 +1789,7 @@ packages:
'@rollup/rollup-darwin-x64@4.46.2':
resolution: {integrity: sha512-SSj8TlYV5nJixSsm/y3QXfhspSiLYP11zpfwp6G/YDXctf3Xkdnk4woJIF5VQe0of2OjzTt8EsxnJDCdHd2xMA==}
+ cpu: [x64]
os: [darwin]
'@rollup/rollup-freebsd-arm64@4.46.2':
@@ -2155,6 +2161,11 @@ packages:
peerDependencies:
vite: ^4.0.0 || ^5.0.0
+ '@uni-ku/root@1.3.2':
+ resolution: {integrity: sha512-0wgUVATOCaFapkwgjbZxp8X0B8eOw3flg/JDPRBYyIumBbVENbZEa57pOi8hl5ogmVDCm+sdNSFWRXOiQIy3tA==}
+ peerDependencies:
+ vite: ^5.0.0
+
'@unocss-applet/preset-applet@0.10.0':
resolution: {integrity: sha512-bN6jaZo0WMQRvKVDisUXAF4Ig2CVDMe8rk6rZDxzWNFZiReMYK97SxS/JTEFAknWSu4C+GYtut+57NPD2PqHrg==}
peerDependencies:
@@ -8968,6 +8979,13 @@ snapshots:
- ts-node
- vue
+ '@uni-ku/root@1.3.2(vite@5.2.8(@types/node@20.19.9)(sass@1.77.8)(terser@5.43.1))':
+ dependencies:
+ '@vue/compiler-sfc': 3.4.21
+ chokidar: 3.6.0
+ jsonc-parser: 3.3.1
+ vite: 5.2.8(@types/node@20.19.9)(sass@1.77.8)(terser@5.43.1)
+
'@unocss-applet/preset-applet@0.10.0(@unocss/core@66.4.0)(@unocss/preset-mini@66.0.0)(@unocss/preset-wind3@66.0.0)':
dependencies:
'@unocss/core': 66.4.0
diff --git a/src/App.ku.vue b/src/App.ku.vue
new file mode 100644
index 0000000..de97b1f
--- /dev/null
+++ b/src/App.ku.vue
@@ -0,0 +1,24 @@
+
+
+
+
+ {{ helloKuRoot }},这里可以配置全局的东西
+
+
+
+
+
diff --git a/src/layouts/default.vue b/src/layouts/default.vue
index d362f86..89d16af 100644
--- a/src/layouts/default.vue
+++ b/src/layouts/default.vue
@@ -2,6 +2,11 @@
import { useThemeStore } from '@/store'
const themeStore = useThemeStore()
+
+const testUniLayoutExposedData = ref('testUniLayoutExposedData')
+defineExpose({
+ testUniLayoutExposedData,
+})
diff --git a/src/pages.json b/src/pages.json
index 54865b0..da4336c 100644
--- a/src/pages.json
+++ b/src/pages.json
@@ -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": "我的"
}
diff --git a/src/pages/about/about.vue b/src/pages/about/about.vue
index 0420c19..fbc200c 100644
--- a/src/pages/about/about.vue
+++ b/src/pages/about/about.vue
@@ -1,6 +1,5 @@
{
- "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({
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index c69423c..b48d454 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -1,7 +1,6 @@
{
- "layout": "tabbar",
"style": {
// 'custom' 表示开启自定义导航栏,默认 'default'
"navigationStyle": "custom",
diff --git a/src/pages/me/me.vue b/src/pages/me/me.vue
index 657291f..5dadfc6 100644
--- a/src/pages/me/me.vue
+++ b/src/pages/me/me.vue
@@ -1,6 +1,5 @@
{
- "layout": "tabbar",
"style": {
// 'custom' 表示开启自定义导航栏,默认 'default'
// "navigationStyle": "custom",
diff --git a/vite.config.ts b/vite.config.ts
index 16f5a91..d891a2a 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -16,6 +16,8 @@ import UniPlatform from '@uni-helper/vite-plugin-uni-platform'
* @see https://github.com/uni-ku/bundle-optimizer
*/
import Optimization from '@uni-ku/bundle-optimizer'
+// https://github.com/uni-ku/root
+import UniKuRoot from '@uni-ku/root'
import dayjs from 'dayjs'
import { visualizer } from 'rollup-plugin-visualizer'
import UnoCSS from 'unocss/vite'
@@ -129,6 +131,8 @@ export default ({ command, mode }) => {
directoryAsNamespace: false, // 是否把目录名作为命名空间前缀,true 时组件名为 目录名+组件名,
dts: 'src/types/components.d.ts', // 自动生成的组件类型声明文件路径(用于 TypeScript 支持)
}),
+ // 若存在改变 pages.json 的插件,请将 UniKuRoot 放置其后
+ UniKuRoot(),
Uni(),
],
define: {