1:index.vue的頁(yè)面,在按鈕上綁定點(diǎn)擊事件,將所要傳遞的參數(shù)放在點(diǎn)擊事件的方法里面。
<text @click="details(item.id)"></text>
2:進(jìn)入methods,將參數(shù)放在方法里面,并且在url跳轉(zhuǎn)路徑后面進(jìn)行拼接。
details(id) {
uni.navigateTo({
url: "details?id="+id,
});
},
3:在pages里面新建一個(gè)details.vue頁(yè)面,接收index.vue傳過(guò)來(lái)的參數(shù)。

4:在onLoad里面打印一下接受到的參數(shù)
onLoad(option) {
console.log(option.id)
},

5:index.vue頁(yè)面的參考代碼
<template>
<view>
<view class="padding-xl" v-for="(item,index) in fenecList.fences" :key="index">
<text @click="details(item.id)">{{item.id}} {{item.name}}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
fenecList: [],
};
},
onLoad() {
this.getList();
},
methods: {
getList() {
uni.request({
url: "../../static/test.json",
method: 'get',
dataType: 'json',
success: (res) => {
console.log(res.data);
this.fenecList = res.data.info;
},
});
},
details(id) {
uni.navigateTo({
url: "details?id="+id,
});
},
},
}
</script>
<style>
</style>
details.vue參考的代碼
<template>
<view>
</view>
</template>
<script>
export default {
data() {
return {
};
},
onLoad(option) {
console.log(option.id)
this.getList(option.id);
},
methods: {
getList(id) {
uni.request({
url: "xxx",
method: 'get',
dataType: 'json',
data: {
"id":"id",
},
success: (res) => {
},
});
},
},
}
</script>
<style>
</style>
test.json
{
"retCode": 1,
"info": {
"configName": "家庭作業(yè)",
"fences": [{
"id": 1,
"name": "測(cè)試區(qū)域一"
},{
"id": 2,
"name": "測(cè)試區(qū)域二"
},{
"id": 3,
"name": "測(cè)試區(qū)域三"
},{
"id": 4,
"name": "測(cè)試區(qū)域四"
}]
}
}