实测有效!!!
<template>
<view>
<view>返回的数据为:</view>
<view>id: {{testdata.id}}</view>
<view>name: {{testdata.name}}</view>
<button type="primary" @click="goNext">跳转到下一页面</button>
</view>
</template>
<script>
export default {
data() {
return {
testdata: {
id: '',
name: ''
}
}
},
onShow() {
let pages = getCurrentPages();
let currPage = pages[pages.length - 1]; //当前页面
let json = currPage.data.testdata;
this.testdata = json;
},
methods: {
goNext() {
uni.navigateTo({
url: '/pages/next/next'
})
}
}
}
</script>
<style>
</style>
<template>
<view>
<button type="primary" @click="goBack">点击返回上一页</button>
</view>
</template>
<script>
export default {
data() {
return {
mydata: {
id: 1,
name: 'test'
}
}
},
methods: {
goBack() {
var pages = getCurrentPages();
var prevPage = pages[pages.length - 2];
prevPage.$vm.testdata = this.mydata;
prevPage.setData(this.mydata);
uni.navigateBack({//返回
delta: 1
})
}
}
}
</script>
<style>
</style>