041组件传值与状态管理绑定的实现方式
从主结构页面中向下传状态管理的值
import storeModel from './stores/model';
const Model = storeModel();
const model = Model.model;
const { getTaskData } = ModelTaskMixin(model);
通过监听url参数变化重新获取模型并更新状态管理
watch(
() => router.currentRoute.value.params.sn,
(newVal, oldVal) => {
if (newVal && newVal !== oldVal) {
getTaskData((newVal as string) || '');
}
},
{
immediate: true,
}
);
使用状态管理值,为获得最新状态采用计算方式获得
const programCom = computed(() => {
const m = model.customConfig.page;
return defineAsyncComponent(() => import(`./index/${m}.vue`));
});
子组件采用全量下探传值
const props = defineProps<{
model: any;
skin?: string;
}>();
向下传递子组件的值的时候,使用计算属性绑定
const props = defineProps<{
model: any;
type: string;
skin?: string;
index: number;
}>();
const treenode = computed(() => props.model.tasks[props.index][props.type]);