Subscribe on changes!

When the parent component adds a timer to change a value, it causes the slot of the child component to be rerendered(父组件添加定时器改变某个值,会导致子组件的slot重新渲染)

avatar
Sep 10th 2020

Version

3.0.0-rc.10

Reproduction link

https://github.com/vuejs/vue-next/issues/2090

Steps to reproduce

What problem does this feature solve?

Reduce the render events of the child components, the slots in my child components do not actually trigger any changes。

code an repro

import { defineComponent, reactive } from "vue";
import moment from "moment";
import headerBox from "@/components/header";
import card from "@/components/card";
import startdevice from "./start_device";
import operation_warm from "./operation_warm";

const staticData = {
  weekcn: ["一", "二", "三", "四", "五", "六", "日"],
};

const data = reactive({
  time: moment(),
});
export default defineComponent({
  components: { headerBox, card, runLog, startdevice, operation_warm },
  created() {
    this.getCdate();
  },
  methods: {
    getCdate() {
      setInterval(() => {
        data.time = moment();
      }, 1000);
    },
  },
  render() {
    return (
      <div>
        <headerBox />
        <div class="view_body">
          <div class="top_box title">
              {data.time.format("YYYY年MM月DD日")}
              <div class="time">{data.time.format("HH:mm:ss")}</div>
              星起{staticData.weekcn[data.time.isoWeekday() - 1]}
          </div>

          <div class="cards-box">
            <card
              class="left_card"
              title="设备启动 "
              vSlots={{
                body: <startdevice />,
              }}
            />
          </div>
        </div>
      </div>
    );
  },
});

image

What is expected?

Do not trigger the rendering of child component slots when the parent component updates data

What is actually happening?

When the parent component updates data, the rendering of the child component slot is triggered

avatar
Sep 10th 2020

As said, provide a boiled down reproduction with no extra dependencies https://jsfiddle.net/n4890y27/

https://new-issue.vuejs.org/?repo=vuejs/vue-router-next#why-repro