1

<script>
        const app = new Vue({
            el: '#app', 
            data:{
                results:{}
            },
            mounted()
            {
                axios.get('{{ route('request.data') }}').then(response=>this.results = response.data)
            }
        });
    </script>
<span class="company-value" v-text="results.request_stats.new"></span>

As in title this is the error I am getting. but When I console.log(object) the value is there and it is not null. So what is the point of this error

Note: object=results.request_stats

3
  • Please add your code. Commented Jun 9, 2018 at 8:28
  • added the code. i am calling an ajax request on the route and it is returning back an object results Commented Jun 9, 2018 at 8:34
  • Please add the relevant code. There is no object, no console.log, and no results.request_stats in your example. Commented Jun 9, 2018 at 8:35

2 Answers 2

1

a work around is to add to your span the following snippet

v-if="results && results.request_stats"
Sign up to request clarification or add additional context in comments.

Comments

0

You have to declare and assign some value like {} or [] to bind , otherwise you will get Undefined error for request_stats.new

const app = new Vue({
            el: '#app', 
            data:{
                results:{request_stats:{}},
                loading:true
            },
            mounted()
            {
              var vm = this;
               setTimeout(function(){ 
                vm.loading = false;
                vm.results.request_stats.new = "Niklesh Raut";
               }, 1000);
            }
        });
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<div id="app">
<div>
<span class="company-value" v-text="results.request_stats.new"></span>
<div v-show="loading">loading...</div>
</div>
</div>

Without assigning, which is giving error

const app = new Vue({
            el: '#app', 
            data:{
                results:{},
                loading:true
            },
            mounted()
            {
              var vm = this;
               setTimeout(function(){ 
                vm.loading = false;
                vm.results.request_stats.new = "Niklesh Raut";
               }, 1000);
            }
        });
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<div id="app">
<div>
<span class="company-value" v-text="results.request_stats.new"></span>
<div v-show="loading">loading...</div>
</div>
</div>

7 Comments

I have to initialize every object and array which can be dynamic when I get them from the server??
@AhmedNawazKhan: Yes boss to bind object.
You can also read about how data binds
well this is insane. the data may be dynamic. you may never know what is comming arrays objects etc
Can you share any situation where you dont know about data type ? Array have object and object have array.
|

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.