首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用vue-select时编译失败

使用vue-select时编译失败
EN

Stack Overflow用户
提问于 2020-02-05 15:37:24
回答 2查看 300关注 0票数 1

我试图创建一个简单的vueJs项目,并在webpack/babel的帮助下编写它。但是,在运行npm来编译项目并启动vue服务器时,我会看到Select.vue模板的编译失败(安装vue-strap时安装的Select.vue ),下面是在我的本地端口上加载的确切错误:

代码语言:javascript
复制
Failed to compile.

./node_modules/vue-loader/lib/template-compiler?{"id":"data-v-5f7db264","hasScoped":true,"buble":{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./node_modules/vue-strap/src/Select.vue
(Emitted value instead of an instance of Error) 
  Error compiling template:

  <div v-el:select :class="classes">
    <div class="form-control dropdown-toggle"
      :disabled="disabled || !hasParent"
      :readonly="readonly"
      @click="toggle()"
      @keyup.esc="show = false"
    >
      <span class="btn-content" v-html="loading ? text.loading : showPlaceholder || selected"></span>
      <span v-if="clearButton&&values.length" class="close" @click="clear()">&times;</span>
    </div>
    <select v-el:sel v-model="value" v-show="show" name="{{name}}" class="secret" :multiple="multiple" :required="required" :readonly="readonly" :disabled="disabled">
      <option v-if="required" value=""></option>
      <option v-for="option in options" :value="option[optionsValue]||option">{{ option[optionsLabel]||option }}</option>
    </select>
    <ul class="dropdown-menu">
      <template v-if="options.length">
        <li v-if="canSearch" class="bs-searchbox">
          <input type="text" placeholder="{{searchText||text.search}}" class="form-control" autocomplete="off"
            v-el:search
            v-model="searchValue"
            @keyup.esc="show = false"
          />
          <span v-show="searchValue" class="close" @click="clearSearch">&times;</span>
        </li>
        <li v-if="required&&!clearButton"><a @mousedown.prevent="clear() && blur()">{{ placeholder || text.notSelected }}</a></li>
        <li v-for="option in options | filterBy searchValue" :id="option[optionsValue]||option">
          <a @mousedown.prevent="select(option[optionsValue],option)">
            <span v-html="option[optionsLabel]||option"></span>
            <span class="glyphicon glyphicon-ok check-mark" v-show="isSelected(option[optionsValue])"></span>
          </a>
        </li>
      </template>
      <slot></slot>
      <div v-if="showNotify && !closeOnSelect" class="notify in" transition="fadein">{{limitText}}</div>
    </ul>
    <div v-if="showNotify && closeOnSelect" class="notify out" transition="fadein"><div>{{limitText}}</div></div>
  </div>

  - name="{{name}}": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of <div id="{{ val }}">, use <div :id="val">.
  - placeholder="{{searchText||text.search}}": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of <div id="{{ val }}">, use <div :id="val">.
  - invalid expression: Unexpected identifier in

    options | filterBy searchValue

  Raw expression: v-for="option in options | filterBy searchValue"


 @ ./node_modules/vue-strap/src/Select.vue 11:0-220
 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

我还附加了我的main.js和App.vue文件,我在其中调用Select.vue组件:

main.js:

代码语言:javascript
复制
import Vue from 'vue'
import App from './App.vue'

new Vue({
  el: '#app',
  render: h => h(App)
})

App.vue

代码语言:javascript
复制
<template>
    <div>
        <app-header></app-header>
        <v-select v-model="selected" :options="['Vue.js','React']"></v-select>
        <app-footer></app-footer>
    </div>
</template>

<script>
import Header from './components/header.vue'
import select from '../node_modules/vue-strap/src/Select.vue'
import Footer from './components/footer.vue'
export default {
    components: {
        'app-header': Header,
        'app-footer': Footer,
        'v-select': select,
    },
    data() {
      return {

      }
    },
}
</script>

<style scoped>

</style>

我想知道为什么我会犯这个错误。最初,我在另一个项目中也出现了这个错误,但是让它去吧,因为我认为这可能是由于我在那里使用的依赖关系的旧版本造成的。但在这个项目中,我使用的是最新的,但它仍然没有编译。此外,页眉和页脚工作正常,在它们中没有问题。任何帮助都是非常感谢的。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-02-05 16:24:43

这些错误解释了这一点:

代码语言:javascript
复制
- name="{{name}}": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of <div id="{{ val }}">, use <div :id="val">.
- placeholder="{{searchText||text.search}}": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of <div id="{{ val }}">, use <div :id="val">.
- invalid expression: Unexpected identifier in

  options | filterBy searchValue

Raw expression: v-for="option in options | filterBy searchValue"
  1. name="{{name}}"替换为:name="name"
  2. placeholder="{{searchText||text.search}}"替换为:placeholder="searchText || text.search"
  3. filterBy被废弃了- 尝试用计算方法替换正在迭代的内容
票数 1
EN

Stack Overflow用户

发布于 2020-02-05 16:29:38

根据您所说的内容和错误中显示的代码,您正在使用以下库:https://github.com/yuche/vue-strap

这个库不再使用,更重要的是,它与您使用的Vue 2.9不兼容。

您可以尝试使用与Vue 2兼容的这个备用叉子,但请记住,您可能需要更改代码库。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60079232

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档