[Vuejs]-I want to pass a variable from vuejs tospring boot

2👍

You are using two endpoints with the same path and method. I think the default for the request mapping is a get, if one is get and the other is post then you need to specify it, or if you plan to use two rest endpoints with the same method you need to make them point to different paths.

@RequestMapping(value = "/", method = RequestMethod.POST)
void getcalcoperation(@RequestParam String calc) {
    calcvalue = calc ;
}

@GetMapping("/") // from spring boot to vue
public String home() {
    return calcvalue;
}

Also, you are using two different APIs for the call to the back-end (fetch and axios) an advice would be to use only one, even though this doesn’t give you any problems.

1👍

The postPost() method must be inside methods object like this

methods:{
  postPost() {
    axios.post(`http://localhost:8085`, {
      body: this.calcoperation
    });
  }
}

And the mounted method will not be invoked automatically.
You might need to put that also into methods and call it manually to set the data into title data property. You may use a callback to achieve it.

Leave a comment