Comments (3)
This is because you need to set options
before you set the values:
created() {
this.options = [...data]
}
Also the search
method seems redundant, Multiselect should filter the results automatically.
from multiselect.
This is a simple example for clarity. In my case, reactive search options are used that I get from the GraphQL API. As well as the data that was received initially from the API. I am thinking about merge options that are pre-passed to v-model.
// BaseSearch.vue
<template>
<Multiselect
v-model="model"
v-bind="$attrs"
:object="true"
:searchable="true"
:loading="loading"
:options="selectOptions"
value-prop="id"
track-by="name"
label="name"
@search-change="search"
/>
</template>
<script lang="ts">
import {
PropType,
defineComponent,
computed,
ref
} from '@vue/composition-api';
import Multiselect from '@vueform/multiselect/dist/multiselect.vue2';
import { useSearchQuery } from '@/graphql';
export default defineComponent({
components: {
Multiselect
},
props: {
value: {
type: [Array, Object, String, Boolean, Number] as PropType<any>
},
type: {
type: String as PropType<'USER' | 'TAG'>,
required: true
}
} as const,
setup(props, { emit }) {
const model = computed({
get: () => props.value,
set: (value: any) => {
emit('input', value);
}
});
const variables = ref({});
const { loading, result } = useSearchQuery(variables);
const relayConnection = computed(() => (
result.value?.search || {
edges: []
}
));
const selectOptions = computed(() => (
relayConnection.value.edges.map(edge => edge.node)
));
const search = (query: string) => {
if (!query) {
return;
}
variables.value = {
query,
type: props.type
};
};
return {
model,
loading,
selectOptions,
search
};
}
});
</script>
My example usage
<BaseSearch
v-model="mainteners"
mode="tags"
type="USER"
/>
// ...
setup(props) {
const mainteners = ref(props.mainteners);
const updateMainteners = {...};
return { mainteners, updateMainteners };
}
from multiselect.
Now if you update to 1.4.0
I believe your initial example will work. I guess that solves the original problem.
from multiselect.
Related Issues (20)
- Blur when option have a lot in mac os
- Different clearIcon svg fill color for dark and light mode HOT 2
- focus() issue HOT 1
- Missing methods in Multiselect type
- Add focus/blur event emits HOT 1
- Clicking the clear icon
- Typescript Build Error HOT 1
- can't add option with space in mobile
- Opening disabled input
- Select does not scroll to selected item when the list is large HOT 2
- `getOption` does not work when `value` is an object. HOT 1
- Empty values in createOption with trimmed value HOT 1
- Prop `closeOnScroll` doesn't work with `appendToBody`
- Expose loading state on async options HOT 1
- appendToBody on async options: dropdown position is incorrect for the first time appearance HOT 1
- [Feature Request] Choose positioning for appendToBody
- Expose default search/filter function
- issue with :append-to-body="true" in a modal.
- In mode "Tags" with an array of objects, an error message should be shown when valueProp can not be found HOT 2
- Tags mode displaying tag count limit
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multiselect.