Vuejs Axios数据未显示

时间:2018-08-01 11:59:04

标签: vue.js vuejs2 axios laravel-5.6

不显示信息的问题在获取时被延迟,我需要任何帮助来解决这个问题。

        <h1>@{{message}}</h1>

        <div class="panel panel-primary">
            <div class="panel-heading">
                <div class="row">
                    <div class="col-md-10"><h3 class="panel-title">Experience</h3></div>
                    <div class="col-md-2 text-right">
                        <button class="btn btn-success">Ajouter</button>
                    </div>
                </div>

            </div>
            <div class="panel-body" >

                <ul class="list-group">
                    <li class="list-group-item" v-for="experience in experiences" >
                        <div class="pull-right">
                            <button class="btn btn-warning btn-sm">Editer</button>
                        </div>
                        <h3>@{{experience.titre}}</h3>
                        <p>@{{experience.body}}</p>
                        <small>@{{experience.debut}} - @{{experience.fin}}</small>
                    </li>

                </ul>

            </div>
        </div>

Vuejs

<script src="{{asset('js/vue.js')}}"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
     var app = new Vue({
       el: '#app',
       data: {
         message: 'Nawfal Kharbouch',
         experiences:[]
       },
       methods:{
        getExperiences:function(){
            axios.get('http://localhost:8080/getexperiences').then(response=>{
                this.experiences=response.data;
                console.log(this.experiences);
            }).catch(function(error){
                console.log('erros : ',error);
            })  
        }
       },
       mounted:function(){
        this.getExperiences();
        console.log(this.experiences);
        }
    })
</script>

在获取信息时未显示信息的问题被延迟了,我需要任何有关此问题的帮助。 //控制台Google Chrome

[__ob__: Observer]
vue.js:8553 You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See more tips at https://vuejs.org/guide/deployment.html
backend.js:1  vue-devtools  Detected Vue v2.5.16 
5:171 (3) [{…}, {…}, {…}, __ob__: Observer];

//图片view vide

2 个答案:

答案 0 :(得分:1)

您不能在promise中传递“ this”,您需要在变量中添加“ this”。

示例:

x    y    xy
1         1
2         2

     4    4
     8    8

答案 1 :(得分:0)

您需要将其传递给变量,而不是直接使用它。

methods:{
        getExperiences:function(){
        var vm = this
            axios.get('http://localhost:8080/getexperiences').then(response=>{
                vm.experiences=response.data;
                console.log(vm.experiences);
            }).catch(function(error){
                console.log('erros : ',error);
            })  
        }
       },