springboot+vue前后端分离测试demo

这里的后端代码需要参考我之前的demo:这里

前端代码使用脚手架。

使用webstorm,idea

 

后端代码:

后端代码其他部分直接参考上个boot练习demo

 

注意需要修改端口否则前后端都是8080端口

 

前端·代码

vue cli3 装有vuex,router,axios插件

新建一个展示页面

 

 具体代码如下所示:

<template>
    <tr>
        <th>id</th>
        <th>name</th>
        <th>gender</th>
    </tr>
    <tr v-for="item in books">
        <td>{{item.id}}</td>
        <td>{{item.stuName}}</td>
        <td>{{item.stuGender}}</td>
    </tr>
</template>
<script>
    import request from '../network/index'
    import axios from 'axios'
    export default {
        name: "ShowBook",
        //组件中需要使用函数返回
        data(){
            return{
                books:[
                    {
                        id:1,
                        stuName:'test',
                        stuGender:'male'
                    },
                ]
            }
        },
        created(){
            //我们不能直接在回调中使用this,因为在回调中使用this我们得到的是函数中的this而不是data中的this
            const _this=this;
            //获取后端数据
            axios.get('http://localhost:8181/findAll').then(function (res) {
                console.log(res);
                _this.books=res.data;
            })
        }
    }
</script>

<style scoped>

</style>

roater中注册组件我们使用懒加载的方式

 

解决跨域问题(这个是固定写法)

 

测试

 

 

 

问题1:dataFn.call is not a function

 

   原因:注意在组件中我们使用数据都是需要在函数中使用

    解决方法:使用return来返回数据,如下图所示

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值