[Vue] provide 出现 undefined、null 的可能情况
传递 Ref 类型,不要解包传递,即 .value
传递非 Ref
类型,导致后代组件不会更新数据。
file:[Father.vue]
const paper = shallowRef<dia.Paper>();
const graph = shallowRef<dia.Graph>();
// 错误传递
del:[provide("paper", paper.value);
provide("graph", graph.value);]:del
// 正确传递
add:[provide("paper", paper);
provide("graph", graph);]:add
onMounted(() => {
const jointjs = createJointJs({
el: "content",
width: "85vw",
height: "75vh",
bgColor: "#ffffff"
});
});
file:[Child.vue]
const paper = inject("paper");