After the network request set the initial value of ref formData from onMounted method not working? It printed but step1 component input value was not changed. We are using vue3 template
How to change input value in this situation?
Hi,
Could you please attach a code that shows how you are setting formData?
setup() {
const store = useStore();
const _stepperObj = ref<StepperComponent | null>(null);
const horizontalWizardRef = ref<HTMLElement | null>(null);
const currentStepIndex = ref(0);
const currentScreening = computed(() => {
return store.getters.currentScreening;
});
const formData = ref<CreateAccount>({
question1:
currentScreening.value.data !== undefined &&
currentScreening.value.data.question1
? "1"
: "0",
question2:
currentScreening.value.data !== undefined &&
currentScreening.value.data.question2
? "1"
: "0",
question3:
currentScreening.value.data !== undefined &&
currentScreening.value.data.question3
? "1"
: "0",
question4_1:
currentScreening.value.data !== undefined &&
currentScreening.value.data.question4[0].isChecked
? "1"
: "0",
question4_2:
currentScreening.value.data !== undefined &&
currentScreening.value.data.question4[1].isChecked
? "1"
: "0",
question4_3:
currentScreening.value.data !== undefined &&
currentScreening.value.data.question4[2].isChecked
? "1"
: "0",
question4_4:
currentScreening.value.data !== undefined &&
currentScreening.value.data.question4[3].isChecked
? "1"
: "0",
question4_5:
currentScreening.value.data !== undefined &&
currentScreening.value.data.question4[4].isChecked
? "1"
: "0",
question4_6:
currentScreening.value.data !== undefined &&
currentScreening.value.data.question4[5].isChecked
? "1"
: "0",
researchTitle: "",
typeOfReview: "standard",
});
const key = ref(0);
onMounted(() => {
store.dispatch(Actions.GET_IRB_SCREENING).then(() => {
console.log("gg");
console.log(formData.value.question1);
console.log(formData.value.question2);
console.log("gg");
key.value += 1;
firstStep();
});
_stepperObj.value = StepperComponent.createInsance(
horizontalWizardRef.value as HTMLElement
);
setCurrentPageBreadcrumbs("New", ["IRB", "Applications"]);
});
It worked on launch from navigation but not working on refresh page or write route and enter
Hi,
Is currentScreening a data object which you are setting with action GET_IRB_SCREENING?
In this case, I think it is better to assign your formData object inside then(()=>{}) section. During an object initialization, it will always contain only your default value.