Browse Source

feat(布局): 在tabbar组件中暴露testUniLayoutExposedData变量

在about页面通过onReady钩子获取暴露的变量,解决onLoad钩子无法获取的问题
feige996 8 tháng trước cách đây
mục cha
commit
91f31839b7
2 tập tin đã thay đổi với 13 bổ sung0 xóa
  1. 4 0
      src/layouts/tabbar.vue
  2. 9 0
      src/pages/about/about.vue

+ 4 - 0
src/layouts/tabbar.vue

@@ -7,6 +7,10 @@ const themeVars: ConfigProviderThemeVars = {
   // buttonPrimaryBgColor: '#07c160',
   // buttonPrimaryColor: '#07c160',
 }
+const testUniLayoutExposedData = ref('testUniLayoutExposedData')
+defineExpose({
+  testUniLayoutExposedData,
+})
 </script>
 
 <template>

+ 9 - 0
src/pages/about/about.vue

@@ -32,6 +32,15 @@ function gotoSubPage() {
     url: '/pages-sub/demo/index',
   })
 }
+// uniLayout里面的变量通过 expose 暴露出来后可以在 onReady 钩子获取到(onLoad 钩子不行)
+const uniLayout = ref()
+onLoad(() => {
+  console.log('onLoad:', uniLayout.value) // onLoad: undefined
+})
+onReady(() => {
+  console.log('onReady:', uniLayout.value) // onReady: Proxy(Object)
+  console.log('onReady:', uniLayout.value.testUniLayoutExposedData) // onReady: testUniLayoutExposedData
+})
 </script>
 
 <template>