【发布时间】:2021-02-21 06:09:00
【问题描述】:
在本地主机 8080 上的 vue.js 代码前端中,因此当单击按钮“r1”时,postpost 方法将“calcoperation”变量发送到本地主机 8085 上的 spring boot。
<div class="home">
<h1>{{title}}</h1>
<h2>You can enter the operation by buttons or by keyboard</h2>
<input type="text" v-model="calcoperation" id="calculationid" >
<br>
<button class="r1" v-on:click="postPost()">=</button>
</div>
</template>
<script>
import axios from 'axios';
export default{
name:"home",
data(){
return{
title: "",
calcoperation: "" ,
errors: []
};
},
mounted(){ //from spring boot to vue
fetch("http://localhost:8085")
.then(response =>{
return response.text();
})
.then(data =>{
this.title=data;
});
},
postPost() {
axios.post(`http://localhost:8085`, {
body: this.calcoperation
})
}
}
</script>
然后我想请求该帖子并将其传递给它 calcvalue,但是当我尝试将 calcvalue 发送到 vue 中的标题变量并将其显示在“h1”中时它不起作用。
@RestController
@CrossOrigin
public class homecontroller {
String calcvalue;
@RequestMapping(value = "http://localhost:8080")
void getcalcoperation(@RequestParam String calc) {
calcvalue = calc ;
}
@GetMapping("/") // from spring boot to vue
public String home() {
return calcvalue;
}
【问题讨论】:
标签: javascript spring-boot vue.js spring-mvc backend