6

The problem of not showing information is delayed in fetching , i need any help for this problem.

        <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>

The problem of not showing information is delayed in fetching , i need any help for this problem. //console 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];

//picture view vide

2 Answers 2

4

Instead of using this directly you need to pass it to a variable.

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);
            })  
        }
       },

Sign up to request clarification or add additional context in comments.

Comments

1

You can not pass "this" inside a promise, you need to add "this" to a variable.

Exemple:

var app = new Vue({
       el: '#app',
       data: {
         message: 'Nawfal Kharbouch',
         experiences:[]
       },
       methods:{
        var self = this;
        getExperiences:function(){
            axios.get('http://localhost:8080/getexperiences').then(response=>{
                self.experiences=response.data;
                console.log(self.experiences);
            }).catch(function(error){
                console.log('erros : ',error);
            })  
        }
       },
        mounted:function(){
        this.getExperiences();
        console.log(this.experiences);
         }
    }) 

1 Comment

When I say the method it gives error.That's right.stackoverflow.com/a/51634629/10636297

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.