Created
August 1, 2020 14:43
-
-
Save PKTseng/4c54b8b5dd08ed782353e69376f2a625 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = new Vue({ | |
el: '#app', | |
data: { | |
filterArray: [], | |
filterText: '', | |
arrayData: [ | |
{ | |
name: '小明', | |
age: 16 | |
}, | |
{ | |
name: '漂亮阿姨', | |
age: 24 | |
}, | |
{ | |
name: '杰倫', | |
age: 20 | |
} | |
], | |
}, | |
filterData: function () { | |
var vm = this; | |
// 這個 this 是指向 data 的,但如果跑 for 迴圈的話,this 的指向會不同 | |
vm.filterArray = vm.arrayData.filter(function (item) { | |
// filterData 目前只向空陣列,而 filter 是 js 的方法,他會把值 return 到 vm.filterArray | |
console.log(vm.filterText, item.name, item.name.match(vm.filterText)) | |
// return item.name.match(vm.filterText); | |
}); | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment