App.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <template>
  2. <div>
  3. <button @click="getStudents">获取学生信息</button>
  4. <button @click="getCars">获取汽车信息</button>
  5. </div>
  6. </template>
  7. <script>
  8. import axios from 'axios'
  9. export default {
  10. name: "App",
  11. methods:{
  12. getStudents(){
  13. axios.get('http://localhost:8080/api/students').then(
  14. response => {
  15. console.log('请求成功了',response.data)
  16. },
  17. error => {
  18. console.log('请求失败了',error.message)
  19. }
  20. )
  21. },
  22. getCars(){
  23. axios.get('http://localhost:8080/demo/cars').then(
  24. response => {
  25. console.log('请求成功了',response.data)
  26. },
  27. error => {
  28. console.log('请求失败了',error.message)
  29. }
  30. )
  31. }
  32. }
  33. };
  34. </script>