Vue2 v-html中如何使用过滤器?

如题。我想在v-html后面使用一个过滤器,代码如下:

<div class="detail" v-html="article | replaceUrl"></div>

但是我发现在Vue2中不能用了,只能在{{}}中过滤,但是{{}}又不能绑定html

求实现方法,感谢

阅读 14.8k
4 个回答

v-html="replaceMethod(article)"

可以使用指令,这个能配合v-html使用,以对v-html里的内容进行再排版

在methods中定义replaceUrl方法,然后传参数return

<template>
......

    <span v-html="replaceUrl(data)"></span>
    
......


</template>

methods:{

    replaceUrl(args){
    
        return "<span style='color:red;'>"+args+"</span>"
    
    }

}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题