Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

masumluf's avatar

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 ?

0 likes
11 replies
masumluf's avatar

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.

tisuchi's avatar

You better show your code and tell us which one you exactly want to reset.

Nakov's avatar

@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's avatar

@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();

masumluf's avatar

@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 ?

Nakov's avatar

@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();
    },
sujancse's avatar

@nakov why not put this.resetWindow(); inside ..then() in case of error exception, he may still need the data?

masumluf's avatar

@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.