在vue3中的App.vue里面如何声明globalData,我这么声明不生效
- 发布:2022-01-05 18:03
- 更新:2024-09-24 14:52
- 阅读:2905
靐齉齾麤龖龗 - 解决不了问题,那就解决提出问题的人
vue3 组合式api里面,当然,这种方式需要hbx的版本>=4.14
<script setup>
defineOptions({
globalData: {
a: 1
}
})
</script>
<script setup>
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app';
import { nextTick, reactive } from 'vue';
const globalData = {
openId: '',
unionId: '',
}
onLaunch(() => {
globalData.openId = '123';
console.log('App Launch');
nextTick(() => {
getApp().globalData = globalData;
})
});
onShow(() => {
console.log('App Show');
});
onHide(() => {
console.log('App Hide');
});
</script>
使用语法糖写法