Skip to content

Is it possible to set the default value of an asyncComputed property? #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zaarheed opened this issue Jun 2, 2018 · 2 comments
Closed

Comments

@zaarheed
Copy link

zaarheed commented Jun 2, 2018

I am using this plugin to render a dynamic list which updates when other properties in the component change.

In my view I have a simple check to see if the computer value has a length of zero to display a "No results message":

<tr v-if="list.length < 1" class="no-results">
    <td colspan="10" class="has-text-centered">No results</td>
</tr>

However, by default, when the component initialises the value for list is null which throws an error saying that the property length of undefinedis not found. Is there any way to set the default value of a computed property? I'd like to avoid filling my view with multiple checks for if the property is null or has a length less than one.

I noticed it's possible to set the global default value, but I don't think this approach will work for me as in other components I am expecting the value to be null.

@zaarheed
Copy link
Author

zaarheed commented Jun 2, 2018

Whoops, I clearly didn't look at the Issues history before posting... (I blame the not-so-obvious title!)

#9

@zaarheed zaarheed closed this as completed Jun 2, 2018
@foxbenjaminfox
Copy link
Owner

For future reference: The second and third code examples of the usage section of the README demonstrate exactly what you were looking for: setting the default value for an individual computed property.

I'm glad you found the solution, even if your had a slightly indirect route to finding it. 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants