When the parent component adds a timer to change a value, it causes the slot of the child component to be rerendered(父组件添加定时器改变某个值,会导致子组件的slot重新渲染)
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。
代码结构
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>
);
},
});