如何在编辑页面的 vue-multiselect 插件中显示数据名称字段?

How can I show data names field in vue-multiselect plugin in edit page?

我有一个 vue laravel SPA,正在处理员工页面的编辑页面。我已经创建了员工页面,可以在 vue-multiselect 插件 (https://vue-multiselect.js.org/) 上显示数据。现在,我可以在编辑页面的 vue-multiselect 中显示数组中的 employee id's。如何设置格式以显示员工姓名?

<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
<script>
    import Multiselect from 'vue-multiselect'

    export default {
        components: { Multiselect },
        data() {
            return {
                employee: {
                    designation_id: [],
                    position_id: [],
                },
                designation_names: {},
                position_names: {}
            }
        },
        methods: {
            updateEmployee() {
                this.axios
                    .patch(`/api/employees/${this.$route.params.id}`, this.employee)
                    .then((res) => {
                        this.$router.push({ name: 'employees' });
                    });
            },
            async getDesignations(id) {
                const { data } = await this.axios.get(`/employees/${id}/designations`);
                this.$set(this.designation_names, id, data.join(', '));
            },
            async getPositions(id) {
                const { data } = await this.axios.get(`/employees/${id}/positions`);
                this.$set(this.position_names, id, data.join(', '));
            },
        },
        created() {
            this.axios
                .get(`/api/employees/${this.$route.params.id}`)
                .then((res) => {
                    this.employee = res.data;
                });
            for(const row of this.rows) { this.getDesignations(row.id); }
            for(const row of this.rows) { this.getPositions(row.id); }
        },
    }
</script>
<template>
    <form @submit.prevent="updateEmployee">
        <div class="flex space-x-6 md:w-3/4">
            <div class="md:w-3/6 mb-4 flex-1">
                    <label class="block text-gray-700 text-sm font-bold mb-2" for="name">First Name</label>
                    <input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline required" name="name" id="name" type="text" placeholder="First Name" tabindex="1" v-model="employee.first_name" />
                </div>
                <div class="md:w-3/6 mb-4 flex-1">
                    <label class="block text-gray-700 text-sm font-bold mb-2" for="name">Last Name</label>
                    <input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline required" name="name" id="name" type="text" placeholder="Last Name" tabindex="2" v-model="employee.last_name" />
                </div>
            </div>
            <div class="flex space-x-6 md:w-3/4">
                <div class="md:w-3/6 mb-4 flex-1">
                <label class="block text-gray-700 text-sm font-bold mb-2 required" for="designation_id">Designation</label>
                <multiselect
                    v-model="employee.designation_id"
                    :options="designation_options" 
                    :custom-label="opt => designation_options.find(designation => designation.id == opt).name"
                    :multiple="true"
                    :taggable="true"
                ></multiselect>
                </div>
                <div class="md:w-3/6 mb-4 flex-1">
                    <label class="block text-gray-700 text-sm font-bold mb-2 required" for="position_id">Position</label>
                    <multiselect
                    v-model="employee.position_id"
                    :options="position_options"
                    :multiple="true"
                    :taggable="true"
                ></multiselect>
                </div>
            </div>
            <div class="flex space-x-6 md:w-3/4">
                <div class="md:w-3/6 mb-4 flex-1">
                    <label class="block text-gray-700 text-sm font-bold mb-2" for="basic_pay">Basic Pay</label>
                    <div class="relative rounded">
                    <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                        <span class="text-gray-700">₱</span>
                    </div>
                    <input class="shadow appearance-none border rounded w-full py-2 pl-8 pr-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline required" name="basic_pay" id="basic_pay" type="number" step="any"  placeholder="00.00" tabindex="5" v-model="employee.basic_pay" />
                    <div class="absolute inset-y-0 right-0 flex items-center"><label for="basic_pay" class="sr-only">Basic Pay</label>
                    </div>
                </div>
            </div>
            <div class="md:w-3/6 mb-4 flex-1">&nbsp;</div>
        </div>
        <button type="submit" class="sm:hidden md:flex bg-blue-500 hover:bg-blue-400 text-white font-bold py-2 px-4 border-b-4 border-blue-700 hover:border-blue-500 rounded outline-none focus:outline-none">Update</button>
    </form>
</template>

我设法通过检索每个字段来解决这个问题,而不是我在单个对象中检索所有的先前代码。

this.axios
    .get(`/api/designations/${this.$route.params.id}`)
    .then((res) => {
        this.form.name = res.data.name;
        this.form.description = res.data.description;
    });

之前:

this.axios
    .get(`/api/designations/${this.$route.params.id}`)
    .then((res) => {
        this.form= res.data;
    });