首页 > 解决方案 > vue中如何使用axios获取id选择的数据

问题描述

app.js:50345 [Vue 警告]:无效的道具:道具“数据”的类型检查失败。预期对象,得到值为“”的字符串。

这就是我路由数据和分页的方式

Route::get('project',function(){
    return App\project::latest()->paginate(5);});

这就是我展示的方式

<td>{{projectownerdata && projectownerdata.project_id}}</td>

这是我在 vue 中的脚本

<script>
    export default {

            data(){
              return{
              projectownerdata :{
              },
               form: new Form({
              project_id:'',
              project_name:'',
              project_code:'',
              tct_number:'',
              project_status:'New',
              address:''

                    })            

                }
            },

            methods:{
      //For Pagination
               getResults(page = 1) {
                     axios.get('api/project?page=' + page)
                      .then(response => {
                        this.projectownerdata = response.data
                })
              },

loadProjects(){
   axios.get('api/project/'+ this.$route.params.id)
        .then(response => {
            this.projectownerdata = response.data
        });

}                        
            },

            created(){
            this.loadProjects();


            },

            }





</script>

标签: laravelvue.jsaxios

解决方案


推荐阅读