我已经调试了 8 个小时,试图找出为什么这个 vue-select 代码不起作用,但仍然没有运气。当我运行它时,它显示一个错误“选项未定义”。我正在使用 npm 将 vue-select 插件安装到我的项目中。我将以下 html 代码放在我的树枝模板中。我确实按照 vue-select 页面上的说明进行操作
<div id="myapp">
<v-select :options="myoptions" label="title">
<template slot="option" slot-scope="option">
<span class="fa" :class="option.icon"></span>
{{ option.title }}
</template>
</v-select>
</div>
这是我的js实现代码的其余部分。
import Vue from 'vue';
import VueSelect from 'vue-select';
Vue.component('v-select', VueSelect)
new Vue({
el: '#myapp',
data: function () {
return {
myoptions: [
{
title: 'Read the Docs',
icon: 'fa-book',
url: 'https://codeclimate.com/github/sagalbot/vue-select'
},
{
title: 'View on GitHub',
icon: 'fa-github',
url: 'https://codeclimate.com/github/sagalbot/vue-select'
},
{
title: 'View on NPM',
icon: 'fa-database',
url: 'https://codeclimate.com/github/sagalbot/vue-select'
},
{
title: 'View Codepen Examples',
icon: 'fa-pencil',
url: 'https://codeclimate.com/github/sagalbot/vue-select'
}
]
}
}
});