vue指令v-html使用过滤器filters功能实例

发布时间:2020-09-28 23:42:02 作者:Chobits
来源:脚本之家 阅读:154

问题

2.0 filters only work in mustache tags and v-bind.

Vue2.0 不再支持在 v-html 中使用过滤器,比如在 1.0 中是这样使用的:

{{{ option.title | highlight }}}

然而,现在不能使用了,Vue2.0 的过滤器现在只能应用在 {{ }} 和 v-bind 中。

然而,嫌麻烦,还想使用怎么办?

解决方法

使用全局方法

put your highlight into methods, and v-html="highlight(option.title)"

可以在 Vue 上定义全局方法:

Vue.prototype.highlight= function (sTitle) {
 // to do
};

然后所有组件上都可以直接用这个方法了:

v-html="highlight(option.title)"

使用 computed 属性

当然,可以使用计算属性 computed,返回原生 html 给 v-html 即可。

使用 $options.filters

You can use $options.filters

v-html="$options.filters.highlight(option.title)".

这个方式在文档中并没有说明,但是这也是可靠的方法。

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

以上就是本次介绍的关于vue指令v-html使用的全部知识点,感谢大家的阅读和对亿速云的支持。

推荐阅读:
  1. 过滤器vue.filters的使用方法实现
  2. 在Vue methods中调用filters里的过滤器实例

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue v-html ers

上一篇:使用Nginx实现服务器中多容器共存的方法

下一篇:Android GridView实现动画效果实现代码

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》