1.添加数据
var newDate = { id: this.id ,name:this.name}//获取数据
this.list.push(newDate)//添加数据
this.id=this.name=this.club=''//清空输入栏
2.删除数据
<input type="button" value="删除" @click="del(index)">
this.list.splice(index,1)//将获得的地址写入,只删除1个,不写‘1’则将后续值全部删除
3.根据关键字查询
<tr v-for="(item,index) in search(keywords)" :key="index">
search(keywords){
// var newList=[]
// this.list.forEach(item => {
// if(item.name.indexOf(keywords) != -1){
// newList.push(item)
// }
// })
var newList = this.list.filter(item => {
if(item.name.includes(keywords)){
return item
}
})
return newList
}
.indexOf(‘’)中数值为空,返回为0
4.关键字过滤
<div id="app">
<p>{{ msg | msgFormat }}</p>
</div>
Vue.filter('msgFormat', function(msg){
return msg.replace(/单纯/g,'的') //正则 /something/g 表示全局选择something
})
<div id="app">
<p>{{ msg | msgFormat('可爱') | test }}</p>
</div>
Vue.filter('msgFormat', function(msg,arg){
return msg.replace(/单纯/g,arg)
})
Vue.filter('test', function(msg){
return msg+"......."
})