加载组件时,我需要在下拉列表中选择值
我正在尝试用 vue-multiselect 让我的代码成为朋友
找到了一个类似的主题 - 但是,该字段中没有出现任何内容 - 如果您然后选择一个值,一切正常链接
其实我得通过axios下载,mini版是这样的
import Multiselect from "vue-multiselect";
export default {
components: {
Multiselect
},
data() {
return {
books: [],
selectedBook: null,
};
},
created() {
this.getBooks();
this.getFav();
},
methods: {
//through axios I get the model and pass it to the list component
getBooks() {
this.books = [
{ id: 1, name: "ABC" },
{ id: 2, name: "QWE" }
];
},
getFav() {
//through axios I get the Id of the model for editing
let responseId = 1;
this.selectedBook = responseId;
},
<template>
...
<multiselect
v-model="selectedBook"
:options="books"
:selected="selectedBook"
track-by="id"
label="name"
:show-labels="false"
placeholder="Choose your book">
<span slot="noResult">No books were found</span>
</multiselect>
<pre class="language-json"><code>{{ selectedBook }}</code></pre>
...
</template>
但是当表单被加载并打开时 - 选择框中没有任何内容,
如果您从列表中进行选择,则模型会更改
我究竟做错了什么?