【问题标题】:vue-truncate-filter not filtering and throwing errorvue-truncate-filter 不过滤并抛出错误
【发布时间】:2017-12-15 20:59:50
【问题描述】:

我无法使用 vue-truncate-filter npm 包。我用这个命令在命令行安装了它:

npm install vue-truncate-filter --save

但是我看到以下错误:

[Vue 警告]:无法解析过滤器:truncate 30 '....'

这是我的模板:

<div v-show="wbwState[index]" v-bind:style="{ margin:`0 ${8}px ${8}px ${8}px`, color: '#C10E40' }">{{ word.english | truncate 5 '....' }}</div>

和:

<div class="eng">{{ word.english | truncate 5 '....' }}</div>

在 main.js 我有:

const VueTruncate = require('vue-truncate-filter');
Vue.use(VueTruncate)

我还尝试在实际组件本身中使用Vue.use()。谁能看到我做错了什么?谢谢!

【问题讨论】:

    标签: javascript vue.js vuejs2 vue-component truncate


    【解决方案1】:

    在 Vue 2 中,filter should be used like this:

    {{ text | truncate(100) }}
    

    所以你的代码应该是

    <div class="eng">{{ word.english | truncate(5) }}</div>
    

    这是working example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-14
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多