I’m have an application where my vue component has a Select control which users can select multiple items within it. I want this property to update based on what the user selects in the dropdown. However I continue to get this error when trying to set it up
[Vue warn]: Write operation failed: computed value is readonly.
The select is used as an input so users can add or remove multiple email addresses Here are the trimmed down versions of the code showing the important bits…
index.vue
JavaScript
x
36
36
1
<template>
2
<q-page class="q-pa-lg justify-evenly">
3
<q-select
4
stack-label
5
clearable
6
filled
7
use-input
8
use-chips
9
multiple
10
hide-dropdown-icon
11
input-debounce="0"
12
new-value-mode="add-unique"
13
v-model="taskRecipients"
14
>
15
</q-select>
16
17
</q-page>
18
</template>
19
20
<script lang="ts">
21
import { defineComponent, ref, computed } from '@vue/composition-api';
22
import { Notify } from 'quasar';
23
24
export default defineComponent({
25
name: 'PageIndex',
26
components: {},
27
setup(props, { root }) {
28
const taskRecipients = computed(() => root.$store.getters['app/taskRecipients']);
29
30
return {
31
taskRecipients,
32
};
33
}
34
});
35
</script>
36
Advertisement
Answer
Try to make the computed property writable by adding a setter :
JavaScript
1
11
11
1
const taskRecipients = computed({
2
3
get:() => root.$store.getters['app/taskRecipients'],
4
5
set:(val)=>{
6
root.$store.dispatch('changeTaskRecipients', val) // run the action that updates the state
7
8
}
9
10
});
11