转载于简书
连接:http://www.jianshu.com/p/29b7eaabd1ba
2.0 filters only work in mustache tags and v-bind.javascript
Vue2.0 再也不支持在 v-html
中使用过滤器,好比在 1.0 中是这样使用的:html
{{{ option.title | highlight }}}
然而,如今不能使用了,Vue2.0 的过滤器如今只能应用在 {{ }}
和 v-bind
中。
然而,嫌麻烦,还想使用怎么办?java
put your
highlight
into methods, andv-html="highlight(option.title)"
spa
能够在 Vue 上定义全局方法:prototype
Vue.prototype.highlight= function (sTitle) { // to do };
而后全部组件上均可以直接用这个方法了:code
v-html="highlight(option.title)"
- What if I have a filter that outputs HTML? Do I have to use a computed property or is there a better way?
- Computed properties are the best way. You get automatic caching.
固然,能够使用计算属性 computed
,返回原生 html
给 v-html
便可。component
You can use $options.filtershtm
v-html="$options.filters.highlight(option.title)".
这个方式在文档中并无说明,可是这也是可靠的方法。ip
You can safely rely on that: $options are the options passed to the Vue constructor when creating a vm (so any component or new Vue). From that point on is just javascript文档