๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
[๊ฐœ๋ฐœ] Practice/Vue.js

[Vue.js] ๋ฐ์ดํ„ฐ ์›๋ณธ ๋ณด์กด์˜ ํ•„์š”์„ฑ ์ดํ•ดํ•˜๊ธฐ ๋ฐ ์ƒํ’ˆ ์ •๋ ฌ ๊ธฐ๋Šฅ ๋งŒ๋“ค๊ธฐ

by Connecting-the-dots 2022. 4. 4.
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’ก ์‹ค์Šต ํฌ์ธํŠธ!


๐Ÿ’œ "๊ฐ€๋‚˜๋‹ค์ˆœ์ •๋ ฌ" ๋ฒ„ํŠผ ๋ฐ ๊ธฐ๋Šฅ ๋งŒ๋“ค๊ธฐ

๐Ÿค ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ

<button class="btn" @click="titleSort()">๊ฐ€๋‚˜๋‹ค์ˆœ์ •๋ ฌ</button>

 

titleSort(){
    this.rooms = [...this.roomsOriginal].sort((a,b) => {
        if (a.title > b.title) return 1;
        if (a.title < b.title) return -1;
        return 0;
    })
}

๐Ÿค ๋ธŒ๋ผ์šฐ์ €๋กœ ๋ฏธ๋ฆฌ๋ณด๊ธฐ


๐Ÿ’œ "๊ฐ€๊ฒฉ์ˆœ์ •๋ ฌ" ๋ฒ„ํŠผ ๋ฐ ๊ธฐ๋Šฅ ๋งŒ๋“ค๊ธฐ

๐Ÿค ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ

<button class="btn" @click="priceSort()">๊ฐ€๊ฒฉ์ˆœ์ •๋ ฌ</button>

 

priceSort(){
    this.rooms = [...this.roomsOriginal].sort((a,b) => a.price - b.price)
}

๐Ÿค ๋ธŒ๋ผ์šฐ์ €๋กœ ๋ฏธ๋ฆฌ๋ณด๊ธฐ


๐Ÿ’œ "๊ฐ€๊ฒฉ์—ญ์ˆœ์ •๋ ฌ" ๋ฒ„ํŠผ ๋ฐ ๊ธฐ๋Šฅ ๋งŒ๋“ค๊ธฐ

๐Ÿค ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ

<button class="btn" @click="priceReverseSort()">๊ฐ€๊ฒฉ์—ญ์ˆœ์ •๋ ฌ</button>

 

priceReverseSort(){
    this.rooms = [...this.roomsOriginal].sort((a,b) => b.price - a.price)
}

๐Ÿค ๋ธŒ๋ผ์šฐ์ €๋กœ ๋ฏธ๋ฆฌ๋ณด๊ธฐ


๐Ÿ’œ "50๋งŒ์›์ดํ•˜" ๋ฒ„ํŠผ ๋ฐ ๊ธฐ๋Šฅ ๋งŒ๋“ค๊ธฐ

๐Ÿค ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ

<button class="btn" @click="under50priceFilter()">50๋งŒ์›์ดํ•˜</button>

 

under50priceFilter(){
    this.rooms = [...this.roomsOriginal].filter((room) =>  room.price <= 500000)
}

๐Ÿค ๋ธŒ๋ผ์šฐ์ €๋กœ ๋ฏธ๋ฆฌ๋ณด๊ธฐ


๐Ÿ’œ "์›๋ž˜๋Œ€๋กœ" ๋ฒ„ํŠผ ๋ฐ ๊ธฐ๋Šฅ ๋งŒ๋“ค๊ธฐ

๐Ÿค ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ

<button class="btn" @click="sortBack()">์›๋ž˜๋Œ€๋กœ</button>

 

sortBack(){
    this.rooms = [...this.roomsOriginal];
}

๐Ÿค ๋ธŒ๋ผ์šฐ์ €๋กœ ๋ฏธ๋ฆฌ๋ณด๊ธฐ

728x90
๋ฐ˜์‘ํ˜•