若依 RouYi-Vue(Spring Boot + Vue)笔记
    		       		warning:
    		            这篇文章距离上次修改已过428天,其中的内容可能已经有所变动。
    		        
        		                
                由于提供的信息不足以明确指出一个特定的代码问题,我将提供一个简单的例子来说明如何使用Spring Boot和Vue.js创建一个简单的应用程序。
Spring Boot Controller 示例:
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
public class HelloController {
 
    @GetMapping("/hello")
    public String hello() {
        return "Hello, Vue!";
    }
}Vue.js 组件示例:
<template>
  <div>
    <h1>{{ message }}</h1>
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      message: ''
    }
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      fetch('/hello')
        .then(response => response.json())
        .then(data => {
          this.message = data;
        });
    }
  }
}
</script>在这个例子中,我们创建了一个Spring Boot后端API端点/hello,然后在Vue.js前端应用中,我们在组件被创建时通过fetch调用这个API,并将返回的数据赋值给组件的数据属性,最终在模板中显示出来。这个例子展示了前后端交互的基本过程。
评论已关闭