如何在Vue中使用Axios获取ID选择的数据

时间:2019-11-22 03:22:50

标签: laravel vue.js axios

  

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>

0 个答案:

没有答案