今天试了试 用vue3的语法获取onload(option)传参,直接从onload中获取 在vue3的声明周期中获取不到
可以用以下这种方法
<template>
<view>{{pageFlag}}</view>
</template>
<script>
import {
onLoad
} from "@dcloudio/uni-app";
import { onMounted,ref } from 'vue';
let onloadVal = null;
export default {
setup() {
onLoad((option) => {
onloadVal=option.detail
});
let pageFlag=ref(0)
onMounted(()=>{
console.log(onloadVal,'我是onMounted');
pageFlag.value=onloadVal
})
return {
pageFlag
}
}
}
</script>
参考以下大神 https://ask.dcloud.net.cn/article/id-39310
使用setup语法糖
手动引入onLoad
<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { onMounted,ref } from 'vue';
let params=ref(null)
onLoad((options) => {
console.log('接收传值:',options)
params=options
});
onMounted(()=>{
console.log(params,'接收到的传值获取')
})
</script>