Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

keep-alive,编辑页面跳到列表页,列表页某条数据的属性有变化

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

如果你不需要从详情页传值到列表页;则可以在列表页跳转时保存跳转的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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...