您的位置:首页 > 产品设计 > UI/UE

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

2018-03-27 20:53 253 查看
1问题原因:Vue2.0 不再支持在 v-html 中使用过滤器解决方法:1: 全局方法(推介)2: computed 属性3: $options.filters(推介)具体用法如下一页:
21:使用全局方法可以在 Vue 上定义全局方法:Vue.prototype.msg= function (msg
a6ca
) {      return msg.replace("\n", "<br>")};然后所有地方上都可以直接用这个方法了:<div  v-html="msg(content)"></div>
32 : computed 属性var appMain= new Vue({      el: '#appMain',      computed :{         content: function (msg) {            return msg.replace("\n", "<br>")          },      },      data: {        content: "XXXXX"     }})页面上:<div>{{content}}</div>
43: $options.filters在定义的vue里的filter添加方法:var appMain= new Vue({      el: '#appMain',      filters:{        msg: function(msg) {            return msg.replace(/\n/g, "<br>") ;        }      },      data: {        content: "XXXXX"     }})然后页面上都可以直接用这个方法了:<div id="appMain">    <div  v-html="$options.filters.msg(content)"></div></div>

vue在html中的使用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐