在 Vue 3 中修改 el-select 组件接收的 prop 值
最近再写vue3项目,需要组件传值,prop获取值然后el-select赋值还可以继续选下拉框值
父组件截图
子组件展示
const props = defineProps({sGID: {type: String,default: "",},
});
const emit = defineEmits(['update:sGID']);
const sGIDOL = ref(props.sGID);
watch(() => props.sGID, (newVal) => {sGIDOL.value = newVal;
});watch(sGIDOL, (newVal) => {emit('update:sGID', newVal);
});
这样就成功了,注意参数要写对