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中的使用
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中的使用
相关文章推荐
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- vue filters过滤器使用
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue filters过滤器的使用方法
- VUE基本指令(v-model,v-html,v-text,v-bind,v-if,v-show,v-for,v-on:click,组件,过滤器)
- vue.js使用v-model指令实现的数据双向绑定功能示例
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- 规避使用 vue 的 v-html 指令的方法
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现
- Vue中使用Froala Editor时,外部方法调用html.insert()插入内容到光标最后停留位置功能实现