I'm begining now with vue js 2. I have this code, which receives dynamic data from the server (laravel 5.3 app), the problem is when i try to declare the users array on the ponent instead of declaring in the Vue() instance (in this case works great):
HTML:
<div id="app">
<my-ponent>
<ul id="users-list">
<li v-for="user in users">{{user.name}}</li>
</ul>
</my-ponent>
</div>
JS:
Vueponent('my-ponent', {
template: '#users-list',
data: function () {
return {
users: []
}
},
mounted: function() {
this.$http.get('http://127.0.0.1:8003/api/test').then((response) => {
console.log(response.body);
this.users = response.body;
}, function() {
alert('brrh');
});
}
});
new Vue({
el: '#app',
});
The error message: "Uncaught ReferenceError: users is not defined"
I'm begining now with vue js 2. I have this code, which receives dynamic data from the server (laravel 5.3 app), the problem is when i try to declare the users array on the ponent instead of declaring in the Vue() instance (in this case works great):
HTML:
<div id="app">
<my-ponent>
<ul id="users-list">
<li v-for="user in users">{{user.name}}</li>
</ul>
</my-ponent>
</div>
JS:
Vue.ponent('my-ponent', {
template: '#users-list',
data: function () {
return {
users: []
}
},
mounted: function() {
this.$http.get('http://127.0.0.1:8003/api/test').then((response) => {
console.log(response.body);
this.users = response.body;
}, function() {
alert('brrh');
});
}
});
new Vue({
el: '#app',
});
The error message: "Uncaught ReferenceError: users is not defined"
Share Improve this question edited Oct 14, 2016 at 14:51 IronAces 1,8931 gold badge28 silver badges37 bronze badges asked Oct 14, 2016 at 14:30 MiguelMiguel 1,9076 gold badges21 silver badges31 bronze badges1 Answer
Reset to default 4Looks like you're trying to do an inline-template
try adding that directive to your <my-ponent>
call.
<div id="app">
<my-ponent inline-template>
<ul id="users-list">
<li v-for="user in users">{{user.name}}</li>
</ul>
</my-ponent>
</div>
You will also have to remove the template parameter from your ponent call
Vue.ponent('my-ponent', {
data: function () {
return {
users: []
}
},
mounted: function() {
this.$http.get('http://127.0.0.1:8003/api/test').then((response) => {
console.log(response.body);
this.users = response.body;
}, function() {
alert('brrh');
});
}
});
new Vue({
el: '#app',
});
jsFiddle