Is there any way to reset data value in vuejs?
Dear Developers, I am trying to get information using an username, since i am using vuejs page doesnt refresh as a result my previous search result do not reset. so when each time i search any item previous value and current value getting added. How can I reset previous value in vuejs ?
same it is not working as i wanted. It reset even my model value, so input field failed to pass any value to controller. as a result nothing showing.
You better show your code and tell us which one you exactly want to reset.
@masumluf if it is only one field, this is what I do:
searchMethod: function() {
// make the request here using the value from the search
// as the very last line reset the data to an empty value:
this.search = '';
}
@nakov nope it is not working that way, @tisuchi please visit that link to see my code https://jsfiddle.net/m68pos9t/
@masumluf you have this.resetWindow(); before you make the post request :) so all your form data gets empty. Still my answer above applies. You need to make the request first, then call this.resetWindow();
@nakov how I would do that ? I when I click on the button I have only one function to trigger. so i need to call this.resetWindow() inside that function. or where should I call it ? could you tell me in details ?
@masumluf here, just your search method a bit modified:
SearchStudent() {
if (!this.form.name){
Swal.fire({
icon: 'error',
title: 'Please Enter User ID',
})
return false;
}
this.loading=true;
const config = { headers: { 'content-Type': 'multipart/Form-data' } };
this.$refs.topProgress.start()
axios.post('/profilecheck',this.form)
.then((res) => {
this.$refs.topProgress.done()
this.result=res.data[0][0];
//console.log(res.data[1]);
this.billing=res.data[3];
this.exam=res.data[2];
this.attendence=res.data[1];
this.behave=res.data[4];
this.countAttendence();
this.countExam();
this.countBilling();
this.countBehave();
this.hide_message=true;
this.profile_image='/images/'+this.result.photo
console.log(this.rating)
this.loading=false;
//console.log(this.attendence_p);
//window.location = '/homework'
})
.catch(error => {
this.loading=false;
this.$refs.topProgress.done()
Swal.fire({
icon: 'error',
title: 'User Not found. Please Type Valid User ID',
})
//window.location.reload()
});
this.resetWindow();
},
@nakov why not put this.resetWindow(); inside ..then() in case of error exception, he may still need the data?
@nakov but still previous value is not resetting. Still when I search by any userid and if i search by the same userid data getting double. like student12 when i frist search by it it shows well. but without page refreshing if i again click search button attendence getting double. Exam result getting duplicate copy . like that . I need to only information what i am getting from API. but my data getting double with previous value.
Please or to participate in this conversation.