1、EventChannel
A页面
uni.navigateTo({
url:'/pages/index/index',
success: (res) => {
res.eventChannel.emit('transmitData', {
data: '12345'
})
}
})
B页面
onLoad(()=>{
const pages = getCurrentPages();
const page = pages[pages.length - 1];
const eventChannel = page.getOpenerEventChannel();
eventChannel.on('transmitData', (data) => {
console.log(data)
})
})
2、pinia
import { defineStore } from 'pinia'
export const useDataStore = defineStore('dataStore', {
state: () => {
return { dataInfo: {} }
}
})
A页面
import { useDataStore } from '@/stores'
useRoomStore().dataInfo= {data:'12345'}
B页面
import { useDataStore } from '@/stores'
const dataInfo = useRoomStore().dataInfo
3、sessionStorage
A页面
sessionStorage.setItem('dataInfo', JSON.stringify({ data:'12345' }))
B页面
const dataInfo = JSON.parse(sessionStorage.getItem('dataInfo'))