vue computed property not able to get dataDetecting an undefined object propertyHow can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How to get the children of the $(this) selector?How can I get query string values in JavaScript?Get the current URL with JavaScript?Sort array of objects by string property valueHow do I get the current date in JavaScript?Iterate through object properties
Anatomically Correct Strange Women In Ponds Distributing Swords
Method to test if a number is a perfect power?
Failed to fetch jessie backports repository
What is the difference between "behavior" and "behaviour"?
Is expanding the research of a group into machine learning as a PhD student risky?
How do I find the solutions of the following equation?
How to write papers efficiently when English isn't my first language?
Class Action - which options I have?
Go Pregnant or Go Home
Is HostGator storing my password in plaintext?
Trouble understanding the speech of overseas colleagues
How do I go from 300 unfinished/half written blog posts, to published posts?
CREATE opcode: what does it really do?
Crossing the line between justified force and brutality
How does buying out courses with grant money work?
Inappropriate reference requests from Journal reviewers
Would this custom Sorcerer variant that can only learn any verbal-component-only spell be unbalanced?
Is there a good way to store credentials outside of a password manager?
How does it work when somebody invests in my business?
Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?
Are student evaluations of teaching assistants read by others in the faculty?
You cannot touch me, but I can touch you, who am I?
Lay out the Carpet
Escape a backup date in a file name
vue computed property not able to get data
Detecting an undefined object propertyHow can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How to get the children of the $(this) selector?How can I get query string values in JavaScript?Get the current URL with JavaScript?Sort array of objects by string property valueHow do I get the current date in JavaScript?Iterate through object properties
I am currently experiencing an issue where the computed()
property is not able to get data. Although data was already initiated in created()
property. Am I doing it wrong? Please advise how I can fix this issue.
const randomPlayers =
template:
`
<input type="text" v-model="search_player">
<div v-for="player in modPlayers" v-if="list_of_random_players!=null">
<p>player.firstname</p>
<p>player.lastname</p>
<div>
`,
props: ['data'],
data ()
return
list_of_random_players: null,
search_player: null
,
created()
this.get_random_players()
,
computed:
modPlayers()
return this.list_of_random_players.filter( person =>
return !this.search_player )
,
methods:
get_random_players: function()
$.post(
url:'random_url'
data:
players: data
).done((success)=>
this.list_of_random_players: JSON.parse(success)
)fail((err)=>
console.log(err)
)
I get the following two errors:
(1) TypeError: Cannot read property 'filter' of null
(2) TypeError: this.list_of_random_players.filter is not a function
javascript vue.js vuejs2 vue-component
add a comment |
I am currently experiencing an issue where the computed()
property is not able to get data. Although data was already initiated in created()
property. Am I doing it wrong? Please advise how I can fix this issue.
const randomPlayers =
template:
`
<input type="text" v-model="search_player">
<div v-for="player in modPlayers" v-if="list_of_random_players!=null">
<p>player.firstname</p>
<p>player.lastname</p>
<div>
`,
props: ['data'],
data ()
return
list_of_random_players: null,
search_player: null
,
created()
this.get_random_players()
,
computed:
modPlayers()
return this.list_of_random_players.filter( person =>
return !this.search_player )
,
methods:
get_random_players: function()
$.post(
url:'random_url'
data:
players: data
).done((success)=>
this.list_of_random_players: JSON.parse(success)
)fail((err)=>
console.log(err)
)
I get the following two errors:
(1) TypeError: Cannot read property 'filter' of null
(2) TypeError: this.list_of_random_players.filter is not a function
javascript vue.js vuejs2 vue-component
1
First, if you initialize data as function i.edata()
you have to return an object. Then you passplayers: data
in your post request but wheredata
comes from ?
– Sovalina
Mar 21 at 16:23
@Sovalina, I got it from props. I updated the code
– ApplePie
Mar 21 at 17:04
add a comment |
I am currently experiencing an issue where the computed()
property is not able to get data. Although data was already initiated in created()
property. Am I doing it wrong? Please advise how I can fix this issue.
const randomPlayers =
template:
`
<input type="text" v-model="search_player">
<div v-for="player in modPlayers" v-if="list_of_random_players!=null">
<p>player.firstname</p>
<p>player.lastname</p>
<div>
`,
props: ['data'],
data ()
return
list_of_random_players: null,
search_player: null
,
created()
this.get_random_players()
,
computed:
modPlayers()
return this.list_of_random_players.filter( person =>
return !this.search_player )
,
methods:
get_random_players: function()
$.post(
url:'random_url'
data:
players: data
).done((success)=>
this.list_of_random_players: JSON.parse(success)
)fail((err)=>
console.log(err)
)
I get the following two errors:
(1) TypeError: Cannot read property 'filter' of null
(2) TypeError: this.list_of_random_players.filter is not a function
javascript vue.js vuejs2 vue-component
I am currently experiencing an issue where the computed()
property is not able to get data. Although data was already initiated in created()
property. Am I doing it wrong? Please advise how I can fix this issue.
const randomPlayers =
template:
`
<input type="text" v-model="search_player">
<div v-for="player in modPlayers" v-if="list_of_random_players!=null">
<p>player.firstname</p>
<p>player.lastname</p>
<div>
`,
props: ['data'],
data ()
return
list_of_random_players: null,
search_player: null
,
created()
this.get_random_players()
,
computed:
modPlayers()
return this.list_of_random_players.filter( person =>
return !this.search_player )
,
methods:
get_random_players: function()
$.post(
url:'random_url'
data:
players: data
).done((success)=>
this.list_of_random_players: JSON.parse(success)
)fail((err)=>
console.log(err)
)
I get the following two errors:
(1) TypeError: Cannot read property 'filter' of null
(2) TypeError: this.list_of_random_players.filter is not a function
javascript vue.js vuejs2 vue-component
javascript vue.js vuejs2 vue-component
edited Mar 21 at 17:11
ApplePie
asked Mar 21 at 15:58
ApplePieApplePie
298311
298311
1
First, if you initialize data as function i.edata()
you have to return an object. Then you passplayers: data
in your post request but wheredata
comes from ?
– Sovalina
Mar 21 at 16:23
@Sovalina, I got it from props. I updated the code
– ApplePie
Mar 21 at 17:04
add a comment |
1
First, if you initialize data as function i.edata()
you have to return an object. Then you passplayers: data
in your post request but wheredata
comes from ?
– Sovalina
Mar 21 at 16:23
@Sovalina, I got it from props. I updated the code
– ApplePie
Mar 21 at 17:04
1
1
First, if you initialize data as function i.e
data()
you have to return an object. Then you pass players: data
in your post request but where data
comes from ?– Sovalina
Mar 21 at 16:23
First, if you initialize data as function i.e
data()
you have to return an object. Then you pass players: data
in your post request but where data
comes from ?– Sovalina
Mar 21 at 16:23
@Sovalina, I got it from props. I updated the code
– ApplePie
Mar 21 at 17:04
@Sovalina, I got it from props. I updated the code
– ApplePie
Mar 21 at 17:04
add a comment |
1 Answer
1
active
oldest
votes
From Vue: "When a Vue instance is created, it adds all the properties found in its data object to Vue’s reactivity system. When the values of those properties change, the view will “react”, updating to match the new values."
So data
is a function that returns an object but as mentioned by @Sovalina you are not returning it so you cannot access its properties. You need to add return
and change null
to []
:
data()
return
list_of_random_players: [],
search_player: []
,
or you can do without return
and like a regular object:
data:
list_of_random_players: [],
search_player: []
When your Vue component is used multiple times, it is better to use it like a function(first case).
"When defining a component, data must be declared as a function that returns the initial data object. Why? Because there will be many instances created using the same definition. If we still use a plain object for data, that same object will be shared by reference across all instance created! By providing a data function, every time a new instance is created we can call it to return a fresh copy of the initial data."
Reference:link
It might be just a typo but you need to add :
to methods
as well.
I am getting the following error:this.list_of_random_players.filter
is not a function. I think it is still null even after the created() was ran
– ApplePie
Mar 21 at 17:04
I actually have two error: (1)TypeError: Cannot read property 'filter' of null
(2)TypeError: this.list_of_random_players.filter is not a function
– ApplePie
Mar 21 at 17:09
1
Then you need to debug your code to see what you are getting back from the REST call.Another thing is try changing the initialization of your data properties fromnull
to[]
– DjSh
Mar 21 at 17:13
1
That was it. I just had to changenull
to[]
to solve it. Thank you!
– ApplePie
Mar 21 at 17:16
1
Then I will update my answer accordingly. Happy to hear that
– DjSh
Mar 21 at 17:17
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284538%2fvue-computed-property-not-able-to-get-data%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
From Vue: "When a Vue instance is created, it adds all the properties found in its data object to Vue’s reactivity system. When the values of those properties change, the view will “react”, updating to match the new values."
So data
is a function that returns an object but as mentioned by @Sovalina you are not returning it so you cannot access its properties. You need to add return
and change null
to []
:
data()
return
list_of_random_players: [],
search_player: []
,
or you can do without return
and like a regular object:
data:
list_of_random_players: [],
search_player: []
When your Vue component is used multiple times, it is better to use it like a function(first case).
"When defining a component, data must be declared as a function that returns the initial data object. Why? Because there will be many instances created using the same definition. If we still use a plain object for data, that same object will be shared by reference across all instance created! By providing a data function, every time a new instance is created we can call it to return a fresh copy of the initial data."
Reference:link
It might be just a typo but you need to add :
to methods
as well.
I am getting the following error:this.list_of_random_players.filter
is not a function. I think it is still null even after the created() was ran
– ApplePie
Mar 21 at 17:04
I actually have two error: (1)TypeError: Cannot read property 'filter' of null
(2)TypeError: this.list_of_random_players.filter is not a function
– ApplePie
Mar 21 at 17:09
1
Then you need to debug your code to see what you are getting back from the REST call.Another thing is try changing the initialization of your data properties fromnull
to[]
– DjSh
Mar 21 at 17:13
1
That was it. I just had to changenull
to[]
to solve it. Thank you!
– ApplePie
Mar 21 at 17:16
1
Then I will update my answer accordingly. Happy to hear that
– DjSh
Mar 21 at 17:17
add a comment |
From Vue: "When a Vue instance is created, it adds all the properties found in its data object to Vue’s reactivity system. When the values of those properties change, the view will “react”, updating to match the new values."
So data
is a function that returns an object but as mentioned by @Sovalina you are not returning it so you cannot access its properties. You need to add return
and change null
to []
:
data()
return
list_of_random_players: [],
search_player: []
,
or you can do without return
and like a regular object:
data:
list_of_random_players: [],
search_player: []
When your Vue component is used multiple times, it is better to use it like a function(first case).
"When defining a component, data must be declared as a function that returns the initial data object. Why? Because there will be many instances created using the same definition. If we still use a plain object for data, that same object will be shared by reference across all instance created! By providing a data function, every time a new instance is created we can call it to return a fresh copy of the initial data."
Reference:link
It might be just a typo but you need to add :
to methods
as well.
I am getting the following error:this.list_of_random_players.filter
is not a function. I think it is still null even after the created() was ran
– ApplePie
Mar 21 at 17:04
I actually have two error: (1)TypeError: Cannot read property 'filter' of null
(2)TypeError: this.list_of_random_players.filter is not a function
– ApplePie
Mar 21 at 17:09
1
Then you need to debug your code to see what you are getting back from the REST call.Another thing is try changing the initialization of your data properties fromnull
to[]
– DjSh
Mar 21 at 17:13
1
That was it. I just had to changenull
to[]
to solve it. Thank you!
– ApplePie
Mar 21 at 17:16
1
Then I will update my answer accordingly. Happy to hear that
– DjSh
Mar 21 at 17:17
add a comment |
From Vue: "When a Vue instance is created, it adds all the properties found in its data object to Vue’s reactivity system. When the values of those properties change, the view will “react”, updating to match the new values."
So data
is a function that returns an object but as mentioned by @Sovalina you are not returning it so you cannot access its properties. You need to add return
and change null
to []
:
data()
return
list_of_random_players: [],
search_player: []
,
or you can do without return
and like a regular object:
data:
list_of_random_players: [],
search_player: []
When your Vue component is used multiple times, it is better to use it like a function(first case).
"When defining a component, data must be declared as a function that returns the initial data object. Why? Because there will be many instances created using the same definition. If we still use a plain object for data, that same object will be shared by reference across all instance created! By providing a data function, every time a new instance is created we can call it to return a fresh copy of the initial data."
Reference:link
It might be just a typo but you need to add :
to methods
as well.
From Vue: "When a Vue instance is created, it adds all the properties found in its data object to Vue’s reactivity system. When the values of those properties change, the view will “react”, updating to match the new values."
So data
is a function that returns an object but as mentioned by @Sovalina you are not returning it so you cannot access its properties. You need to add return
and change null
to []
:
data()
return
list_of_random_players: [],
search_player: []
,
or you can do without return
and like a regular object:
data:
list_of_random_players: [],
search_player: []
When your Vue component is used multiple times, it is better to use it like a function(first case).
"When defining a component, data must be declared as a function that returns the initial data object. Why? Because there will be many instances created using the same definition. If we still use a plain object for data, that same object will be shared by reference across all instance created! By providing a data function, every time a new instance is created we can call it to return a fresh copy of the initial data."
Reference:link
It might be just a typo but you need to add :
to methods
as well.
edited Mar 21 at 17:17
answered Mar 21 at 16:47
DjShDjSh
132114
132114
I am getting the following error:this.list_of_random_players.filter
is not a function. I think it is still null even after the created() was ran
– ApplePie
Mar 21 at 17:04
I actually have two error: (1)TypeError: Cannot read property 'filter' of null
(2)TypeError: this.list_of_random_players.filter is not a function
– ApplePie
Mar 21 at 17:09
1
Then you need to debug your code to see what you are getting back from the REST call.Another thing is try changing the initialization of your data properties fromnull
to[]
– DjSh
Mar 21 at 17:13
1
That was it. I just had to changenull
to[]
to solve it. Thank you!
– ApplePie
Mar 21 at 17:16
1
Then I will update my answer accordingly. Happy to hear that
– DjSh
Mar 21 at 17:17
add a comment |
I am getting the following error:this.list_of_random_players.filter
is not a function. I think it is still null even after the created() was ran
– ApplePie
Mar 21 at 17:04
I actually have two error: (1)TypeError: Cannot read property 'filter' of null
(2)TypeError: this.list_of_random_players.filter is not a function
– ApplePie
Mar 21 at 17:09
1
Then you need to debug your code to see what you are getting back from the REST call.Another thing is try changing the initialization of your data properties fromnull
to[]
– DjSh
Mar 21 at 17:13
1
That was it. I just had to changenull
to[]
to solve it. Thank you!
– ApplePie
Mar 21 at 17:16
1
Then I will update my answer accordingly. Happy to hear that
– DjSh
Mar 21 at 17:17
I am getting the following error:
this.list_of_random_players.filter
is not a function. I think it is still null even after the created() was ran– ApplePie
Mar 21 at 17:04
I am getting the following error:
this.list_of_random_players.filter
is not a function. I think it is still null even after the created() was ran– ApplePie
Mar 21 at 17:04
I actually have two error: (1)
TypeError: Cannot read property 'filter' of null
(2) TypeError: this.list_of_random_players.filter is not a function
– ApplePie
Mar 21 at 17:09
I actually have two error: (1)
TypeError: Cannot read property 'filter' of null
(2) TypeError: this.list_of_random_players.filter is not a function
– ApplePie
Mar 21 at 17:09
1
1
Then you need to debug your code to see what you are getting back from the REST call.Another thing is try changing the initialization of your data properties from
null
to []
– DjSh
Mar 21 at 17:13
Then you need to debug your code to see what you are getting back from the REST call.Another thing is try changing the initialization of your data properties from
null
to []
– DjSh
Mar 21 at 17:13
1
1
That was it. I just had to change
null
to []
to solve it. Thank you!– ApplePie
Mar 21 at 17:16
That was it. I just had to change
null
to []
to solve it. Thank you!– ApplePie
Mar 21 at 17:16
1
1
Then I will update my answer accordingly. Happy to hear that
– DjSh
Mar 21 at 17:17
Then I will update my answer accordingly. Happy to hear that
– DjSh
Mar 21 at 17:17
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284538%2fvue-computed-property-not-able-to-get-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
First, if you initialize data as function i.e
data()
you have to return an object. Then you passplayers: data
in your post request but wheredata
comes from ?– Sovalina
Mar 21 at 16:23
@Sovalina, I got it from props. I updated the code
– ApplePie
Mar 21 at 17:04