Javascript 使用合成API对用户输入作出反应的Quasar Select
我有一个应用程序,其中我的vue组件有一个选择控件,用户可以在其中选择多个项目。我希望此属性根据用户在下拉列表中选择的内容进行更新。但是,在尝试设置时,我仍然会遇到此错误Javascript 使用合成API对用户输入作出反应的Quasar Select,javascript,vue.js,vue-component,Javascript,Vue.js,Vue Component,我有一个应用程序,其中我的vue组件有一个选择控件,用户可以在其中选择多个项目。我希望此属性根据用户在下拉列表中选择的内容进行更新。但是,在尝试设置时,我仍然会遇到此错误 [Vue warn]:写入操作失败:计算值为只读。 选择用作输入,因此用户可以添加或删除多个电子邮件地址 下面是代码的精简版本,显示了重要的位 index.vue <template> <q-page class="q-pa-lg justify-evenly">
[Vue warn]:写入操作失败:计算值为只读。
选择用作输入,因此用户可以添加或删除多个电子邮件地址
下面是代码的精简版本,显示了重要的位
index.vue
<template>
<q-page class="q-pa-lg justify-evenly">
<q-select
stack-label
clearable
filled
use-input
use-chips
multiple
hide-dropdown-icon
input-debounce="0"
new-value-mode="add-unique"
v-model="taskRecipients"
>
</q-select>
</q-page>
</template>
<script lang="ts">
import { defineComponent, ref, computed } from '@vue/composition-api';
import { Notify } from 'quasar';
export default defineComponent({
name: 'PageIndex',
components: {},
setup(props, { root }) {
const taskRecipients = computed(() => root.$store.getters['app/taskRecipients']);
return {
taskRecipients,
};
}
});
</script>
从'@vue/composition api'导入{defineComponent,ref,computed};
从“类星体”导入{Notify};
导出默认定义组件({
名称:'PageIndex',
组件:{},
设置(道具,{root}){
const taskRecipients=computed(()=>root.$store.getters['app/taskRecipients']);
返回{
任务接受者,
};
}
});
尝试通过添加setter使计算属性可写:
const taskRecipients = computed({
get:() => root.$store.getters['app/taskRecipients'],
set:(val)=>{
root.$store.dispatch('changeTaskRecipients', val) // run the action that updates the state
}
});
尝试通过添加setter使计算属性可写:
const taskRecipients = computed({
get:() => root.$store.getters['app/taskRecipients'],
set:(val)=>{
root.$store.dispatch('changeTaskRecipients', val) // run the action that updates the state
}
});
这样做是正确的吗?只是好奇:)我想是的。我对CompositionAPI和vue项目还是新手。所以我很感谢您的帮助是的,这是将存储状态绑定到inputIs的最佳方式,这是正确的方式吗?只是好奇:)我想是的。我对CompositionAPI和vue项目还是新手。因此,我很感谢您的帮助是的,这是将存储状态绑定到输入的最佳方式