如果你不需要从详情页传值到列表页;则可以在列表页跳转时保存跳转的id;然后在activated钩子中判断id来修改列表数据;
给你举个例子:
<template>
<div>
<ul>
<li v-for="item in list" :key="item.id">
<div>{{ item.id }}</div>
<div>{{ item.status }}</div>
<div>{{ item.content }}</div>
<div><button @click="goto(item.id)">Go to detail</button></div>
</li>
</ul>
</div>
</template>
<script>
export default {
name: "p-test",
components: {},
data() {
return {
id: null,
list: [
{
id: 1,
content: "123",
status: 1
},
{
id: 2,
content: "456",
status: 3
}
]
};
},
activated() {
if (this.id) {
this.list = this.list.map(item => {
if (item.id == this.id) {
return {
...item,
status: 299988
};
}
return item;
});
this.id = null;
}
},
methods: {
goto(id) {
this.id = id;
this.$router.push({ path: "/privacy-policy", query: { id } });
}
}
};
</script>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…