代码之家  ›  专栏  ›  技术社区  ›  mana

Vue选择插槽范围未定义

  •  0
  • mana  · 技术社区  · 6 年前

    我已经调试了8个小时,试图找出为什么这个VueSelect代码不工作,但仍然没有运气。当我运行它时,它显示一个错误“ 选项未定义 “。我正在使用NPM将Vue Select插件安装到我的项目中。我把下面的HTML代码放在我的twig模板中。我确实按照上面的说明 vue-select page

    <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'
                    }
                ]
            }
        }
    });
    
    2 回复  |  直到 6 年前
        1
  •  1
  •   Nuwan Attanayake    6 年前

      "dependencies": {
        "vue": "^2.5.16",
        "vue-select": "^2.4.0"
      },
    

    <template>
      <div id="app">
        <v-select :options="options" label="title">
                <template slot="option" slot-scope="option">
                    <span class="fa" :class="option.icon"></span>
                        {{ option.title }}
                </template>
        </v-select>
      </div>
    </template>
    
    <script>
    export default {
      name: 'app',
      data: function() {
            return {
                options: [
                    {
                        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'
                    }
                ]
            }
          }
    }
    </script>
    
    <style>
    #app {
      font-family: 'Avenir', Helvetica, Arial, sans-serif;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      text-align: center;
      color: #2c3e50;
      margin-top: 60px;
    }
    </style>
    
        2
  •  0
  •   mana    6 年前