3

I have a component which takes a property called 'endpoints' from the store, adjusts it slightly...

computed: {
            ...mapState(['endpoints']),
            adjustedEndpoints () {
                if (this.endpoints){
                    return this.endpoints.map(x => {
                        x.displayName = x.name;
                        return x;
                    })
                }
            },

...and passes it to a table component in the template:

    <b-table show-empty
             stacked="md"
             :items="adjustedEndpoints"
             :fields="fields"
             :current-page="currentPage"
             :per-page="perPage"
             :filter="filter"
             :sort-by.sync="sortBy"
             :sort-desc.sync="sortDesc"
             :sort-direction="sortDirection"
             @filtered="onFiltered"
    >

The issue is that when I edit an endpoint's properties, I see it change in the Vue component state, but this is not reflected in the rendered component until reload. I am guessing that the adjustedEndpoints() function is not being called automatically.

How can I fix this?

11
  • 1
    Is displayName part of each endpoint before your computed runs? Commented Jun 5, 2018 at 13:51
  • 1
    Vue is not able to detect new property additions. You will need to use Vue.set (or this.$set). Commented Jun 5, 2018 at 13:53
  • 1
    Possibly, this.$set(x, 'displayName', x.name). Commented Jun 5, 2018 at 13:59
  • 1
    How is the property changed? Commented Jun 5, 2018 at 14:04
  • 1
    Here is what I'm trying to understand; you are passing adjustedEndpoints to b-table. If I understand correctly, for now, the first render, that renders correctly and the displayName gets to the b-table and renders as you expect. Then, at some point, you change an endpoint, but the b-table doesn't update the way you expect? If that is the case, how exactly do you change the endpoint? I ask because, as mentioned above, Vue cannot always detect changes to an object or an array depending on how you update it which means that adjustedEndoints may not run after you change endpoint. Commented Jun 5, 2018 at 14:11

1 Answer 1

3

Found the problem.

In my initial state in the Vuex store, I did not declare the 'endpoints' property.

That was the entire problem.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.