Use Vue global filters used in filtering content added crud time

 Use filters
    msgFormt filter method is your own definition,
    Vue.filter is a global filter you define yourself. No s
    Ha filter value must be returned by retuen
    Vue.filter("msgFormt",function (msg,th) {
       // first parameter method msgFormt
       // The second parameter msg, is the data source,
       // The third parameter, in their own <p> {{msg | msgFormt ( "Feiyu")}} parameter transfer </ p> in 'Feiyu'
       return msg.replace (/ simple / g, th)
    });
 

 

<div id="app">
 <p>{{ msg | msgFormt }}</p>
     <-! MsgFormt is a filter ->
</div>

<Script> 
    Vue.filter ( "msgFormt", function (MSG) {
         return msg.replace (/ simple / g, "evil" )
    })
    
was vm = new Vue ({
   el:"#app",
   data:{
       msg: "I was a mere boy, alone, I innocently asked, who are simple people."
   }   
})
</script>

Finally, it will output the page content to replace the original class

I am an evil teenager, I, innocently asked an evil, evil man who is

 

<div id="app">
    <! - --- parameter can freely pass through replacement value ->
 <P> {{msg | msgFormt ( "Feiyu")}} </ p> <- msgFormt is a filter -!>
</div>


<script>
    // Define a global filter --- 
        Vue.filter ( "msgFormt", function (MSG, TH) {
        return msg.replace (/ simple / G, TH)
    });

    vm=new Vue({
        el:"#app",
        data:{
            msg: "I, simply ask a simple, simple people who are"
        }
    });

Feiyu final output, I asked Feiyu, who is the person Feiyu

 

Guess you like

Origin www.cnblogs.com/IwishIcould/p/12006627.html