vue-truncate-filter 不过滤并抛出错误

vue-truncate-filter not filtering and throwing error

我无法使用 vue-truncate-filter npm 包。我使用命令行和以下命令安装它:

npm install vue-truncate-filter --save

但是我看到以下错误:

[Vue warn]: Failed to resolve filter: truncate 30 '....'

这是我的模板:

<div v-show="wbwState[index]" v-bind:style="{ margin:`0 px px 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()。谁能看到我做错了什么?谢谢!

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

{{ text | truncate(100) }}

所以你的代码应该是

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

这里是working example.