Skip to content
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

returning a promise in the data hook raises warnings in console #187

Closed
kfirba opened this issue Oct 17, 2015 · 1 comment
Closed

returning a promise in the data hook raises warnings in console #187

kfirba opened this issue Oct 17, 2015 · 1 comment

Comments

@kfirba
Copy link

kfirba commented Oct 17, 2015

Hello.

I have a simple registration page which loads some data from the server before I show the form. When the data is being loaded I get 2 warnings in the console:

[Vue warn]: You are setting a non-existent path "ok" on a vm instance. Consider pre-initializing the property with the "data" option for more reliable reactivity and better performance.

[Vue warn]: You are setting a non-existent path "data" on a vm instance. Consider pre-initializing the property with the "data" option for more reliable reactivity and better performance.

My hook and method:

route: {
        data: function (transition) {
            return this.fetchTags()
        }
    },

    methods: {
        fetchTags: function () {
            return this.$http.get('tags', function(data, status) {
                this.tags = data.data
            }).error(function(data, status) {
                console.warn(data.error.message)
            })
        },
      // ...

Why is it returning warning in the console if I did exactly as the documentation suggests to return a promise? Did I need to do something in another way?

EDIT:

It seems like what it does is running the $set method on the Promise object that is being returned which has the ok and data keys.

How can I not run it? All I really want to do is to fetch the tags, update the this.tags array and only then show the route. How can I achieve that?

_Note: I'm using vue-resource for my http requests._

@kfirba
Copy link
Author

kfirba commented Oct 17, 2015

Well, it seems like what I need to do is to return an object form the promise:

fetchTags: function () {
            return this.$http.get('tags', function(data, status) {
                return { tags: data.data }
            }).error(function(data, status) {
                console.warn(data.error.message)
            })
        },

But what do I do if I need to fetch another resource? maybe fetchTags and fetchStatuses? how would that look like with the data hook?

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

1 participant