0

I have a component command-button wrapping a Vuetify v-btn component.

command-button receives a property called disabled of type boolean, non-required and false by default.

command-button is being used inside another component called toolbar where inside a v-for loop I add the command-button using a configuration array of actions objects passed to toolbar as a property.

<command-button
  v-for="(action, index) in actions"
  :key="index"
  :label="action.label"
  :disabled="action.disabled"
  @click="action.handler"
></command-button>

When I use my toolbar component in my view component like this:

<toolbar :actions="actions"></toolbar>

I declare the actions of the toolbar in the data of my view component, as follows:

data() {
  return {
    ...        
    actions: [
      {
        label: "Delete",
        handler: this.onDelete,
        disabled: this.disable // This can be a computed or a data element
      },
      {
          label: "Add",
          handler: this.onAdd
      }
    ],
    ...
  },

The issue is that the command-button is not being disabled dynamically, no matter if I use a computed or a member in data. It only works if I use the literal true inside the actions configuration object. Making some debugging, the value received inside toolbar for the disabled attribute of actions element is undefined.

2
  • Are you getting label attribute? Commented Nov 4, 2020 at 12:07
  • Yes, the buttons are redered with the label without issues Commented Nov 4, 2020 at 12:17

1 Answer 1

1

You can't reference a computed property in your data object as it won't be defined when the instance is created. You could add a watcher on this.disable and update the value of actions[0].disabled when it changes.

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

1 Comment

I resolved with an event instead a watcher. But indeed the fact of I cannot use computed or other data members as values for data members, clarified me a lot... Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.