Vue: v-if “TypeError: Cannot read property 'length' of undefined”









up vote
1
down vote

favorite












I have a Rails 5.1.6 api that provides an endpoint with the following data:
enter image description here



I am trying to retrieve the Entities data to Vue.js with axios, but so far, though no errors are being thrown, the data is not showing in the views. Here are the relevant files:



#src/components/Entities.vue
<template>
<div class="entities">
<h1>Entities</h1>
<div v-if="entities.length > 0" class="table-wrap">
<div>
<router-link v-bind:to=" name: 'NewEntity' " class="">Add Entity</router-link>
</div>
<table>
<tr>
<td>Title</td>
<td width="550">Description</td>
<td width="100" align="center">Action</td>
</tr>
<tr v-for="entity in entities">
<td> entity.title </td>
<td> entity.description </td>
<td align="center">
<router-link v-bind:to=" name: 'EditEntity', params: id: entity._id ">Edit</router-link> |
<a href="#" @click="deleteEntity(entity._id)">Delete</a>
</td>
</tr>
</table>
</div>
<div v-else>
There are no entities.. Lets add one now <br /><br />
<router-link v-bind:to=" name: 'NewEntity' " class="add_entity_link">Add Entity</router-link>
</div>
</div>
</template>


<script>
import EntitiesService from '@/services/EntitiesService'
export default
name: 'entities',
data ()
return
entities:

,
mounted ()
this.getEntities()
,
methods:
async getEntities ()
const response = await EntitiesService.fetchEntities()
this.entities = response.data.entities



</script>


#src/services/EntitiesService.js:

import Api from '@/services/Api'

export default
fetchEntities ()
return Api().get('/entities')




#src/services/Api.js

mport axios from 'axios'

export default() =>
return axios.create(
baseURL: 'http://localhost:3000'
)




#Railsapp/config/initializers/cors.rb

Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'http://localhost:3000'

resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end


I have spent hours trying to see what I am doing wrong, but I can't locate the problem. Any help would be much appreciated.



U
new error
Updated cors in initializers to be:



Rails.application.config.middleware.insert_before 0, Rack::Cors do

allow do
origins '*'
resource '/*', :headers => :any, :methods => :patch
end
end


, now I am getting this:



vue.esm.js?efeb:591 [Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined"

found in

---> <Entities> at src/components/Entities.vue
<App> at src/App.vue
<Root>
warn @ vue.esm.js?efeb:591
logError @ vue.esm.js?efeb:1737
globalHandleError @ vue.esm.js?efeb:1732
handleError @ vue.esm.js?efeb:1721
Vue._render @ vue.esm.js?efeb:4546
updateComponent @ vue.esm.js?efeb:2788
get @ vue.esm.js?efeb:3142
run @ vue.esm.js?efeb:3219
flushSchedulerQueue @ vue.esm.js?efeb:2981
(anonymous) @ vue.esm.js?efeb:1837
flushCallbacks @ vue.esm.js?efeb:1758
Promise.then (async)
microTimerFunc @ vue.esm.js?efeb:1806
nextTick @ vue.esm.js?efeb:1850
queueWatcher @ vue.esm.js?efeb:3068
update @ vue.esm.js?efeb:3209
notify @ vue.esm.js?efeb:697
reactiveSetter @ vue.esm.js?efeb:1014
proxySetter @ vue.esm.js?efeb:3300
_callee$ @ Entities.vue?716d:47
tryCatch @ runtime.js?4a57:62
invoke @ runtime.js?4a57:296
prototype.(anonymous function) @ runtime.js?4a57:114
step @ asyncToGenerator.js?7b11:17
(anonymous) @ asyncToGenerator.js?7b11:28
Promise.then (async)
step @ asyncToGenerator.js?7b11:27
(anonymous) @ asyncToGenerator.js?7b11:35
F @ _export.js?90cd:36
(anonymous) @ asyncToGenerator.js?7b11:14
getEntities @ Entities.vue?716d:45
mounted @ Entities.vue?716d:42
callHook @ vue.esm.js?efeb:2921
insert @ vue.esm.js?efeb:4158
invokeInsertHook @ vue.esm.js?efeb:5960
patch @ vue.esm.js?efeb:6179
Vue._update @ vue.esm.js?efeb:2660
updateComponent @ vue.esm.js?efeb:2788
get @ vue.esm.js?efeb:3142
Watcher @ vue.esm.js?efeb:3131
mountComponent @ vue.esm.js?efeb:2795
Vue.$mount @ vue.esm.js?efeb:8540
Vue.$mount @ vue.esm.js?efeb:10939
Vue._init @ vue.esm.js?efeb:4640
Vue @ vue.esm.js?efeb:4729
(anonymous) @ main.js?1c90:10
./src/main.js @ app.js:1826
__webpack_require__ @ app.js:679
fn @ app.js:89
0 @ app.js:1859
__webpack_require__ @ app.js:679
(anonymous) @ app.js:725
(anonymous) @ app.js:728
vue.esm.js?efeb:1741 TypeError: Cannot read property 'length' of undefined
at Proxy.render (eval at ./node_modules/vue-loader/lib/template-compiler/index.js?"id":"data-v-23d09f71","hasScoped":false,"transformToRequire":"video":["src","poster"],"source":"src","img":"src","image":"xlink:href","buble":"transforms":!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/components/Entities.vue (app.js:1661), <anonymous>:8:18)
at VueComponent.Vue._render (vue.esm.js?efeb:4544)
at VueComponent.updateComponent (vue.esm.js?efeb:2788)
at Watcher.get (vue.esm.js?efeb:3142)
at Watcher.run (vue.esm.js?efeb:3219)
at flushSchedulerQueue (vue.esm.js?efeb:2981)
at Array.eval (vue.esm.js?efeb:1837)
at flushCallbacks (vue.esm.js?efeb:1758)`
enter code here









share|improve this question























  • In the developer console, under network tab, can you see the request being made to the rails app?
    – Derek Pollard
    Nov 10 at 19:36











  • forgot to check there. Access to XMLHttpRequest at 'http://localhost:3000/entities' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. createError.js?16d0:16 Uncaught (in promise) Error: Network Error at createError (createError.js?16d0:16) at XMLHttpRequest.handleError (xhr.js?ec6c:87) . I'll see if that is it.
    – user2799827
    Nov 10 at 19:47










  • That is most definitely it! You need to add the appropriate CORS headers to your rails app for it to be able to access the endpoint
    – Derek Pollard
    Nov 10 at 19:48










  • Updated cors in initializers, now I am getting this:
    – user2799827
    Nov 10 at 20:21














up vote
1
down vote

favorite












I have a Rails 5.1.6 api that provides an endpoint with the following data:
enter image description here



I am trying to retrieve the Entities data to Vue.js with axios, but so far, though no errors are being thrown, the data is not showing in the views. Here are the relevant files:



#src/components/Entities.vue
<template>
<div class="entities">
<h1>Entities</h1>
<div v-if="entities.length > 0" class="table-wrap">
<div>
<router-link v-bind:to=" name: 'NewEntity' " class="">Add Entity</router-link>
</div>
<table>
<tr>
<td>Title</td>
<td width="550">Description</td>
<td width="100" align="center">Action</td>
</tr>
<tr v-for="entity in entities">
<td> entity.title </td>
<td> entity.description </td>
<td align="center">
<router-link v-bind:to=" name: 'EditEntity', params: id: entity._id ">Edit</router-link> |
<a href="#" @click="deleteEntity(entity._id)">Delete</a>
</td>
</tr>
</table>
</div>
<div v-else>
There are no entities.. Lets add one now <br /><br />
<router-link v-bind:to=" name: 'NewEntity' " class="add_entity_link">Add Entity</router-link>
</div>
</div>
</template>


<script>
import EntitiesService from '@/services/EntitiesService'
export default
name: 'entities',
data ()
return
entities:

,
mounted ()
this.getEntities()
,
methods:
async getEntities ()
const response = await EntitiesService.fetchEntities()
this.entities = response.data.entities



</script>


#src/services/EntitiesService.js:

import Api from '@/services/Api'

export default
fetchEntities ()
return Api().get('/entities')




#src/services/Api.js

mport axios from 'axios'

export default() =>
return axios.create(
baseURL: 'http://localhost:3000'
)




#Railsapp/config/initializers/cors.rb

Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'http://localhost:3000'

resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end


I have spent hours trying to see what I am doing wrong, but I can't locate the problem. Any help would be much appreciated.



U
new error
Updated cors in initializers to be:



Rails.application.config.middleware.insert_before 0, Rack::Cors do

allow do
origins '*'
resource '/*', :headers => :any, :methods => :patch
end
end


, now I am getting this:



vue.esm.js?efeb:591 [Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined"

found in

---> <Entities> at src/components/Entities.vue
<App> at src/App.vue
<Root>
warn @ vue.esm.js?efeb:591
logError @ vue.esm.js?efeb:1737
globalHandleError @ vue.esm.js?efeb:1732
handleError @ vue.esm.js?efeb:1721
Vue._render @ vue.esm.js?efeb:4546
updateComponent @ vue.esm.js?efeb:2788
get @ vue.esm.js?efeb:3142
run @ vue.esm.js?efeb:3219
flushSchedulerQueue @ vue.esm.js?efeb:2981
(anonymous) @ vue.esm.js?efeb:1837
flushCallbacks @ vue.esm.js?efeb:1758
Promise.then (async)
microTimerFunc @ vue.esm.js?efeb:1806
nextTick @ vue.esm.js?efeb:1850
queueWatcher @ vue.esm.js?efeb:3068
update @ vue.esm.js?efeb:3209
notify @ vue.esm.js?efeb:697
reactiveSetter @ vue.esm.js?efeb:1014
proxySetter @ vue.esm.js?efeb:3300
_callee$ @ Entities.vue?716d:47
tryCatch @ runtime.js?4a57:62
invoke @ runtime.js?4a57:296
prototype.(anonymous function) @ runtime.js?4a57:114
step @ asyncToGenerator.js?7b11:17
(anonymous) @ asyncToGenerator.js?7b11:28
Promise.then (async)
step @ asyncToGenerator.js?7b11:27
(anonymous) @ asyncToGenerator.js?7b11:35
F @ _export.js?90cd:36
(anonymous) @ asyncToGenerator.js?7b11:14
getEntities @ Entities.vue?716d:45
mounted @ Entities.vue?716d:42
callHook @ vue.esm.js?efeb:2921
insert @ vue.esm.js?efeb:4158
invokeInsertHook @ vue.esm.js?efeb:5960
patch @ vue.esm.js?efeb:6179
Vue._update @ vue.esm.js?efeb:2660
updateComponent @ vue.esm.js?efeb:2788
get @ vue.esm.js?efeb:3142
Watcher @ vue.esm.js?efeb:3131
mountComponent @ vue.esm.js?efeb:2795
Vue.$mount @ vue.esm.js?efeb:8540
Vue.$mount @ vue.esm.js?efeb:10939
Vue._init @ vue.esm.js?efeb:4640
Vue @ vue.esm.js?efeb:4729
(anonymous) @ main.js?1c90:10
./src/main.js @ app.js:1826
__webpack_require__ @ app.js:679
fn @ app.js:89
0 @ app.js:1859
__webpack_require__ @ app.js:679
(anonymous) @ app.js:725
(anonymous) @ app.js:728
vue.esm.js?efeb:1741 TypeError: Cannot read property 'length' of undefined
at Proxy.render (eval at ./node_modules/vue-loader/lib/template-compiler/index.js?"id":"data-v-23d09f71","hasScoped":false,"transformToRequire":"video":["src","poster"],"source":"src","img":"src","image":"xlink:href","buble":"transforms":!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/components/Entities.vue (app.js:1661), <anonymous>:8:18)
at VueComponent.Vue._render (vue.esm.js?efeb:4544)
at VueComponent.updateComponent (vue.esm.js?efeb:2788)
at Watcher.get (vue.esm.js?efeb:3142)
at Watcher.run (vue.esm.js?efeb:3219)
at flushSchedulerQueue (vue.esm.js?efeb:2981)
at Array.eval (vue.esm.js?efeb:1837)
at flushCallbacks (vue.esm.js?efeb:1758)`
enter code here









share|improve this question























  • In the developer console, under network tab, can you see the request being made to the rails app?
    – Derek Pollard
    Nov 10 at 19:36











  • forgot to check there. Access to XMLHttpRequest at 'http://localhost:3000/entities' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. createError.js?16d0:16 Uncaught (in promise) Error: Network Error at createError (createError.js?16d0:16) at XMLHttpRequest.handleError (xhr.js?ec6c:87) . I'll see if that is it.
    – user2799827
    Nov 10 at 19:47










  • That is most definitely it! You need to add the appropriate CORS headers to your rails app for it to be able to access the endpoint
    – Derek Pollard
    Nov 10 at 19:48










  • Updated cors in initializers, now I am getting this:
    – user2799827
    Nov 10 at 20:21












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a Rails 5.1.6 api that provides an endpoint with the following data:
enter image description here



I am trying to retrieve the Entities data to Vue.js with axios, but so far, though no errors are being thrown, the data is not showing in the views. Here are the relevant files:



#src/components/Entities.vue
<template>
<div class="entities">
<h1>Entities</h1>
<div v-if="entities.length > 0" class="table-wrap">
<div>
<router-link v-bind:to=" name: 'NewEntity' " class="">Add Entity</router-link>
</div>
<table>
<tr>
<td>Title</td>
<td width="550">Description</td>
<td width="100" align="center">Action</td>
</tr>
<tr v-for="entity in entities">
<td> entity.title </td>
<td> entity.description </td>
<td align="center">
<router-link v-bind:to=" name: 'EditEntity', params: id: entity._id ">Edit</router-link> |
<a href="#" @click="deleteEntity(entity._id)">Delete</a>
</td>
</tr>
</table>
</div>
<div v-else>
There are no entities.. Lets add one now <br /><br />
<router-link v-bind:to=" name: 'NewEntity' " class="add_entity_link">Add Entity</router-link>
</div>
</div>
</template>


<script>
import EntitiesService from '@/services/EntitiesService'
export default
name: 'entities',
data ()
return
entities:

,
mounted ()
this.getEntities()
,
methods:
async getEntities ()
const response = await EntitiesService.fetchEntities()
this.entities = response.data.entities



</script>


#src/services/EntitiesService.js:

import Api from '@/services/Api'

export default
fetchEntities ()
return Api().get('/entities')




#src/services/Api.js

mport axios from 'axios'

export default() =>
return axios.create(
baseURL: 'http://localhost:3000'
)




#Railsapp/config/initializers/cors.rb

Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'http://localhost:3000'

resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end


I have spent hours trying to see what I am doing wrong, but I can't locate the problem. Any help would be much appreciated.



U
new error
Updated cors in initializers to be:



Rails.application.config.middleware.insert_before 0, Rack::Cors do

allow do
origins '*'
resource '/*', :headers => :any, :methods => :patch
end
end


, now I am getting this:



vue.esm.js?efeb:591 [Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined"

found in

---> <Entities> at src/components/Entities.vue
<App> at src/App.vue
<Root>
warn @ vue.esm.js?efeb:591
logError @ vue.esm.js?efeb:1737
globalHandleError @ vue.esm.js?efeb:1732
handleError @ vue.esm.js?efeb:1721
Vue._render @ vue.esm.js?efeb:4546
updateComponent @ vue.esm.js?efeb:2788
get @ vue.esm.js?efeb:3142
run @ vue.esm.js?efeb:3219
flushSchedulerQueue @ vue.esm.js?efeb:2981
(anonymous) @ vue.esm.js?efeb:1837
flushCallbacks @ vue.esm.js?efeb:1758
Promise.then (async)
microTimerFunc @ vue.esm.js?efeb:1806
nextTick @ vue.esm.js?efeb:1850
queueWatcher @ vue.esm.js?efeb:3068
update @ vue.esm.js?efeb:3209
notify @ vue.esm.js?efeb:697
reactiveSetter @ vue.esm.js?efeb:1014
proxySetter @ vue.esm.js?efeb:3300
_callee$ @ Entities.vue?716d:47
tryCatch @ runtime.js?4a57:62
invoke @ runtime.js?4a57:296
prototype.(anonymous function) @ runtime.js?4a57:114
step @ asyncToGenerator.js?7b11:17
(anonymous) @ asyncToGenerator.js?7b11:28
Promise.then (async)
step @ asyncToGenerator.js?7b11:27
(anonymous) @ asyncToGenerator.js?7b11:35
F @ _export.js?90cd:36
(anonymous) @ asyncToGenerator.js?7b11:14
getEntities @ Entities.vue?716d:45
mounted @ Entities.vue?716d:42
callHook @ vue.esm.js?efeb:2921
insert @ vue.esm.js?efeb:4158
invokeInsertHook @ vue.esm.js?efeb:5960
patch @ vue.esm.js?efeb:6179
Vue._update @ vue.esm.js?efeb:2660
updateComponent @ vue.esm.js?efeb:2788
get @ vue.esm.js?efeb:3142
Watcher @ vue.esm.js?efeb:3131
mountComponent @ vue.esm.js?efeb:2795
Vue.$mount @ vue.esm.js?efeb:8540
Vue.$mount @ vue.esm.js?efeb:10939
Vue._init @ vue.esm.js?efeb:4640
Vue @ vue.esm.js?efeb:4729
(anonymous) @ main.js?1c90:10
./src/main.js @ app.js:1826
__webpack_require__ @ app.js:679
fn @ app.js:89
0 @ app.js:1859
__webpack_require__ @ app.js:679
(anonymous) @ app.js:725
(anonymous) @ app.js:728
vue.esm.js?efeb:1741 TypeError: Cannot read property 'length' of undefined
at Proxy.render (eval at ./node_modules/vue-loader/lib/template-compiler/index.js?"id":"data-v-23d09f71","hasScoped":false,"transformToRequire":"video":["src","poster"],"source":"src","img":"src","image":"xlink:href","buble":"transforms":!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/components/Entities.vue (app.js:1661), <anonymous>:8:18)
at VueComponent.Vue._render (vue.esm.js?efeb:4544)
at VueComponent.updateComponent (vue.esm.js?efeb:2788)
at Watcher.get (vue.esm.js?efeb:3142)
at Watcher.run (vue.esm.js?efeb:3219)
at flushSchedulerQueue (vue.esm.js?efeb:2981)
at Array.eval (vue.esm.js?efeb:1837)
at flushCallbacks (vue.esm.js?efeb:1758)`
enter code here









share|improve this question















I have a Rails 5.1.6 api that provides an endpoint with the following data:
enter image description here



I am trying to retrieve the Entities data to Vue.js with axios, but so far, though no errors are being thrown, the data is not showing in the views. Here are the relevant files:



#src/components/Entities.vue
<template>
<div class="entities">
<h1>Entities</h1>
<div v-if="entities.length > 0" class="table-wrap">
<div>
<router-link v-bind:to=" name: 'NewEntity' " class="">Add Entity</router-link>
</div>
<table>
<tr>
<td>Title</td>
<td width="550">Description</td>
<td width="100" align="center">Action</td>
</tr>
<tr v-for="entity in entities">
<td> entity.title </td>
<td> entity.description </td>
<td align="center">
<router-link v-bind:to=" name: 'EditEntity', params: id: entity._id ">Edit</router-link> |
<a href="#" @click="deleteEntity(entity._id)">Delete</a>
</td>
</tr>
</table>
</div>
<div v-else>
There are no entities.. Lets add one now <br /><br />
<router-link v-bind:to=" name: 'NewEntity' " class="add_entity_link">Add Entity</router-link>
</div>
</div>
</template>


<script>
import EntitiesService from '@/services/EntitiesService'
export default
name: 'entities',
data ()
return
entities:

,
mounted ()
this.getEntities()
,
methods:
async getEntities ()
const response = await EntitiesService.fetchEntities()
this.entities = response.data.entities



</script>


#src/services/EntitiesService.js:

import Api from '@/services/Api'

export default
fetchEntities ()
return Api().get('/entities')




#src/services/Api.js

mport axios from 'axios'

export default() =>
return axios.create(
baseURL: 'http://localhost:3000'
)




#Railsapp/config/initializers/cors.rb

Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'http://localhost:3000'

resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end


I have spent hours trying to see what I am doing wrong, but I can't locate the problem. Any help would be much appreciated.



U
new error
Updated cors in initializers to be:



Rails.application.config.middleware.insert_before 0, Rack::Cors do

allow do
origins '*'
resource '/*', :headers => :any, :methods => :patch
end
end


, now I am getting this:



vue.esm.js?efeb:591 [Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined"

found in

---> <Entities> at src/components/Entities.vue
<App> at src/App.vue
<Root>
warn @ vue.esm.js?efeb:591
logError @ vue.esm.js?efeb:1737
globalHandleError @ vue.esm.js?efeb:1732
handleError @ vue.esm.js?efeb:1721
Vue._render @ vue.esm.js?efeb:4546
updateComponent @ vue.esm.js?efeb:2788
get @ vue.esm.js?efeb:3142
run @ vue.esm.js?efeb:3219
flushSchedulerQueue @ vue.esm.js?efeb:2981
(anonymous) @ vue.esm.js?efeb:1837
flushCallbacks @ vue.esm.js?efeb:1758
Promise.then (async)
microTimerFunc @ vue.esm.js?efeb:1806
nextTick @ vue.esm.js?efeb:1850
queueWatcher @ vue.esm.js?efeb:3068
update @ vue.esm.js?efeb:3209
notify @ vue.esm.js?efeb:697
reactiveSetter @ vue.esm.js?efeb:1014
proxySetter @ vue.esm.js?efeb:3300
_callee$ @ Entities.vue?716d:47
tryCatch @ runtime.js?4a57:62
invoke @ runtime.js?4a57:296
prototype.(anonymous function) @ runtime.js?4a57:114
step @ asyncToGenerator.js?7b11:17
(anonymous) @ asyncToGenerator.js?7b11:28
Promise.then (async)
step @ asyncToGenerator.js?7b11:27
(anonymous) @ asyncToGenerator.js?7b11:35
F @ _export.js?90cd:36
(anonymous) @ asyncToGenerator.js?7b11:14
getEntities @ Entities.vue?716d:45
mounted @ Entities.vue?716d:42
callHook @ vue.esm.js?efeb:2921
insert @ vue.esm.js?efeb:4158
invokeInsertHook @ vue.esm.js?efeb:5960
patch @ vue.esm.js?efeb:6179
Vue._update @ vue.esm.js?efeb:2660
updateComponent @ vue.esm.js?efeb:2788
get @ vue.esm.js?efeb:3142
Watcher @ vue.esm.js?efeb:3131
mountComponent @ vue.esm.js?efeb:2795
Vue.$mount @ vue.esm.js?efeb:8540
Vue.$mount @ vue.esm.js?efeb:10939
Vue._init @ vue.esm.js?efeb:4640
Vue @ vue.esm.js?efeb:4729
(anonymous) @ main.js?1c90:10
./src/main.js @ app.js:1826
__webpack_require__ @ app.js:679
fn @ app.js:89
0 @ app.js:1859
__webpack_require__ @ app.js:679
(anonymous) @ app.js:725
(anonymous) @ app.js:728
vue.esm.js?efeb:1741 TypeError: Cannot read property 'length' of undefined
at Proxy.render (eval at ./node_modules/vue-loader/lib/template-compiler/index.js?"id":"data-v-23d09f71","hasScoped":false,"transformToRequire":"video":["src","poster"],"source":"src","img":"src","image":"xlink:href","buble":"transforms":!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/components/Entities.vue (app.js:1661), <anonymous>:8:18)
at VueComponent.Vue._render (vue.esm.js?efeb:4544)
at VueComponent.updateComponent (vue.esm.js?efeb:2788)
at Watcher.get (vue.esm.js?efeb:3142)
at Watcher.run (vue.esm.js?efeb:3219)
at flushSchedulerQueue (vue.esm.js?efeb:2981)
at Array.eval (vue.esm.js?efeb:1837)
at flushCallbacks (vue.esm.js?efeb:1758)`
enter code here






vuejs2 axios






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 2:14









Matt Morgan

2,1362820




2,1362820










asked Nov 10 at 19:24









user2799827

608




608











  • In the developer console, under network tab, can you see the request being made to the rails app?
    – Derek Pollard
    Nov 10 at 19:36











  • forgot to check there. Access to XMLHttpRequest at 'http://localhost:3000/entities' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. createError.js?16d0:16 Uncaught (in promise) Error: Network Error at createError (createError.js?16d0:16) at XMLHttpRequest.handleError (xhr.js?ec6c:87) . I'll see if that is it.
    – user2799827
    Nov 10 at 19:47










  • That is most definitely it! You need to add the appropriate CORS headers to your rails app for it to be able to access the endpoint
    – Derek Pollard
    Nov 10 at 19:48










  • Updated cors in initializers, now I am getting this:
    – user2799827
    Nov 10 at 20:21
















  • In the developer console, under network tab, can you see the request being made to the rails app?
    – Derek Pollard
    Nov 10 at 19:36











  • forgot to check there. Access to XMLHttpRequest at 'http://localhost:3000/entities' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. createError.js?16d0:16 Uncaught (in promise) Error: Network Error at createError (createError.js?16d0:16) at XMLHttpRequest.handleError (xhr.js?ec6c:87) . I'll see if that is it.
    – user2799827
    Nov 10 at 19:47










  • That is most definitely it! You need to add the appropriate CORS headers to your rails app for it to be able to access the endpoint
    – Derek Pollard
    Nov 10 at 19:48










  • Updated cors in initializers, now I am getting this:
    – user2799827
    Nov 10 at 20:21















In the developer console, under network tab, can you see the request being made to the rails app?
– Derek Pollard
Nov 10 at 19:36





In the developer console, under network tab, can you see the request being made to the rails app?
– Derek Pollard
Nov 10 at 19:36













forgot to check there. Access to XMLHttpRequest at 'http://localhost:3000/entities' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. createError.js?16d0:16 Uncaught (in promise) Error: Network Error at createError (createError.js?16d0:16) at XMLHttpRequest.handleError (xhr.js?ec6c:87) . I'll see if that is it.
– user2799827
Nov 10 at 19:47




forgot to check there. Access to XMLHttpRequest at 'http://localhost:3000/entities' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. createError.js?16d0:16 Uncaught (in promise) Error: Network Error at createError (createError.js?16d0:16) at XMLHttpRequest.handleError (xhr.js?ec6c:87) . I'll see if that is it.
– user2799827
Nov 10 at 19:47












That is most definitely it! You need to add the appropriate CORS headers to your rails app for it to be able to access the endpoint
– Derek Pollard
Nov 10 at 19:48




That is most definitely it! You need to add the appropriate CORS headers to your rails app for it to be able to access the endpoint
– Derek Pollard
Nov 10 at 19:48












Updated cors in initializers, now I am getting this:
– user2799827
Nov 10 at 20:21




Updated cors in initializers, now I am getting this:
– user2799827
Nov 10 at 20:21












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










If I had to guess, your problem is here:



async getEntities () 
const response = await EntitiesService.fetchEntities()
this.entities = response.data.entities //



response.data probably exists, but it seems unlikely that response.data has a key called entities. You're not doing anything in your service layer to marshal the simple array in the response.data into entities.



Maybe something like:



async getEntities () 
const response = await EntitiesService.fetchEntities()
this.entities = response.data // looks like your array is probably here



In any case, this error:




"TypeError: Cannot read property 'length' of undefined"




is probably trying to tell you that this.entities has been assigned to undefined inside your Vue component. Fix that.






share|improve this answer
















  • 1




    Seem so simple when you say it like that... Seriously. problem solved. Trying to learn javascript and Api consumption. This has saved me a bunch of time. Thanks!
    – user2799827
    Nov 10 at 22:40










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242613%2fvue-v-if-typeerror-cannot-read-property-length-of-undefined%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










If I had to guess, your problem is here:



async getEntities () 
const response = await EntitiesService.fetchEntities()
this.entities = response.data.entities //



response.data probably exists, but it seems unlikely that response.data has a key called entities. You're not doing anything in your service layer to marshal the simple array in the response.data into entities.



Maybe something like:



async getEntities () 
const response = await EntitiesService.fetchEntities()
this.entities = response.data // looks like your array is probably here



In any case, this error:




"TypeError: Cannot read property 'length' of undefined"




is probably trying to tell you that this.entities has been assigned to undefined inside your Vue component. Fix that.






share|improve this answer
















  • 1




    Seem so simple when you say it like that... Seriously. problem solved. Trying to learn javascript and Api consumption. This has saved me a bunch of time. Thanks!
    – user2799827
    Nov 10 at 22:40














up vote
2
down vote



accepted










If I had to guess, your problem is here:



async getEntities () 
const response = await EntitiesService.fetchEntities()
this.entities = response.data.entities //



response.data probably exists, but it seems unlikely that response.data has a key called entities. You're not doing anything in your service layer to marshal the simple array in the response.data into entities.



Maybe something like:



async getEntities () 
const response = await EntitiesService.fetchEntities()
this.entities = response.data // looks like your array is probably here



In any case, this error:




"TypeError: Cannot read property 'length' of undefined"




is probably trying to tell you that this.entities has been assigned to undefined inside your Vue component. Fix that.






share|improve this answer
















  • 1




    Seem so simple when you say it like that... Seriously. problem solved. Trying to learn javascript and Api consumption. This has saved me a bunch of time. Thanks!
    – user2799827
    Nov 10 at 22:40












up vote
2
down vote



accepted







up vote
2
down vote



accepted






If I had to guess, your problem is here:



async getEntities () 
const response = await EntitiesService.fetchEntities()
this.entities = response.data.entities //



response.data probably exists, but it seems unlikely that response.data has a key called entities. You're not doing anything in your service layer to marshal the simple array in the response.data into entities.



Maybe something like:



async getEntities () 
const response = await EntitiesService.fetchEntities()
this.entities = response.data // looks like your array is probably here



In any case, this error:




"TypeError: Cannot read property 'length' of undefined"




is probably trying to tell you that this.entities has been assigned to undefined inside your Vue component. Fix that.






share|improve this answer












If I had to guess, your problem is here:



async getEntities () 
const response = await EntitiesService.fetchEntities()
this.entities = response.data.entities //



response.data probably exists, but it seems unlikely that response.data has a key called entities. You're not doing anything in your service layer to marshal the simple array in the response.data into entities.



Maybe something like:



async getEntities () 
const response = await EntitiesService.fetchEntities()
this.entities = response.data // looks like your array is probably here



In any case, this error:




"TypeError: Cannot read property 'length' of undefined"




is probably trying to tell you that this.entities has been assigned to undefined inside your Vue component. Fix that.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 20:53









Matt Morgan

2,1362820




2,1362820







  • 1




    Seem so simple when you say it like that... Seriously. problem solved. Trying to learn javascript and Api consumption. This has saved me a bunch of time. Thanks!
    – user2799827
    Nov 10 at 22:40












  • 1




    Seem so simple when you say it like that... Seriously. problem solved. Trying to learn javascript and Api consumption. This has saved me a bunch of time. Thanks!
    – user2799827
    Nov 10 at 22:40







1




1




Seem so simple when you say it like that... Seriously. problem solved. Trying to learn javascript and Api consumption. This has saved me a bunch of time. Thanks!
– user2799827
Nov 10 at 22:40




Seem so simple when you say it like that... Seriously. problem solved. Trying to learn javascript and Api consumption. This has saved me a bunch of time. Thanks!
– user2799827
Nov 10 at 22:40

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242613%2fvue-v-if-typeerror-cannot-read-property-length-of-undefined%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20