1.全局方法(推荐)
2.computed 属性
3.$options.filters (推荐)
使用全局方法
vue.prototype.msg=function(msg){
return msg.replace("\n","
")
}
commputed属性
var appMain = new Vue({
data:{
content:“xxx”
},
el:"#appMain",
computed:{
content:function(msg){
return msg.replace("\n","
")
}
}
})
$options.filters
在定义的vue里的filter添加方法
var appMain=new Vue({
el:"#appMain",
filters:{
msg:function(msg){
return msg.replace(/\n/g,"
")
}
},
data:{
content:“xxx”
}
})
作者:xiaoHelloWord
来源:优快云
原文:https://blog.youkuaiyun.com/xiaoHelloWord/article/details/96920235
版权声明:本文为博主原创文章,转载请附上博文链接!