Skip to content

Instantly share code, notes, and snippets.

@PKTseng

PKTseng/index.js

Created Aug 1, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.