data中的数据:
data:{
days:[
{title:'昨天',methods:'dayBefore'},
{title:'今天',methods:'today'},
{title:'近7天',methods:firstSevenDays},
{title:'近30天',methods:'firstThirtyDays'},
]
},
methods:{
getDays:function(methodsWords){ //关键字
this[methodsWords]();
},
dayBefore:function(){
console.log("dayBefore")
} ,
firstSevenDays:function(){
console.log("firstSevenDays")
} ,
today:function(){
console.log("today")
} ,
firstThirtyDays:function(){
console.log("firstThirtyDays")
} ,
}
html:
<ul>
<li v-for="(day,index) in days" class="days" @click="getDays(day.methods)"></li>
</ul>