2๊ฐ์ง ๋ฐฉ๋ฒ ์กด์ฌ
- node.js ํ๊ฒฝ์ผ๋ก ๊ตฌ๋(node.js ๋ฐํ์ ํ๊ฒฝ ํ์, ์๋น์ค ๊ตฌ๋ ์ ์๋ฒ์ port ๋ค๋ฅด๊ฒ ๊ตฌ์ฑ)
- ๊ธฐ์กด thyemeleafํ์ผ์ script๋ง ์ถ๊ฐ(thyemelaf ๋ ๋๋ง ์ดํ ์กฐ์ํ๋ ๋ฐฉ์์ด๋ผ node.js ๋ถํ์)
์ฌ๊ธฐ์ 2๋ฒ ์งธ ๋ฐฉ๋ฒ ์ฑํ
๊ธฐ์กด html์ body ํ๊ทธ์์ Vue.js ๊ด๋ จ script import(์ค์ ๋ฐฐํฌ ์์ jsํ์ผ ์ง์ import ๊ถ์ฅ)
<!DOCTYPE html>
<html lang="ko"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<!-- head -->
<th:block th:replace="fragments/head :: headFragment"></th:block>
<body>
<div class="wrap">
<main class="main">
<!-- Content -->
<th:block layout:fragment="content"></th:block>
</main>
</div>
<script src="/js/ui.js"></script>
<!-- vue.js import(์ด์์์๋ lib ์ง์ ์ฐธ์กฐํ ๊ฒ) -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<!-- Axios import(์ด์์์๋ lib ์ง์ ์ฐธ์กฐํ ๊ฒ) -->
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<!-- ๊ณตํต js ์ถ๊ฐ -->
<script src="/js/cmmn.js"></script>
<!-- Content script -->
<th:block layout:fragment="script"></th:block>
</body>
</html>
vue.js๋ฅผ ์ ํ div root id ์ค์ (์์)
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/popup.html}">
<!-- Script -->
<script layout:fragment="script" th:inline="javascript" type="text/javascript">
</script>
<th:block layout:fragment="content">
<!-- <div class="contents">-->
<div class="contents" id="app"> <!-- vue.js๋ฅผ ์ ์ฉํ๊ธฐ ์ํด id๋ฅผ "app"์ผ๋ก ์ค์ -->
<h2 class="tit">์ฃผ์๋ก</h2>
<form id="searchForm">
<div class="search-box">
<!-- ๊ฒ์์กฐ๊ฑด -->
<ul>
<li class="full">
<label>์ฌ์๋ช
</label>
<div class="form-row w100">
<div class="col-9">
<input type="text" class="input-default" id="name" v-model="empNm" name="empNm" th:value="${param.empNm}"/>
</div>
<div class="form-inline">
<button class="btn btn-normal" type="button" @click="searchByName">๊ฒ์</button>
<!-- <button class="btn btn-normal" type="button" id="searchBtn">๊ฒ์</button>-->
<button class="btn btn-gray" type="button" id="formResetBtn">์ด๊ธฐํ</button>
</div>
</div>
</li>
</ul>
</div>
</form>
<div class="tbl scroll-x" id="searchlist">
<div class="flex-box justify">
<p class="section-tit">์ฌ์ ๋ชฉ๋ก</p>
</div>
<!-- ๊ฐ๋ก ์คํฌ๋กค์ ๊ฒฝ์ฐ scroll-x ํด๋์ค ์ถ๊ฐ -->
<div class="tbl scroll-x">
<table>
<caption>์ฌ์์น์ธ ์ ์ฒญ</caption>
<colgroup>
<col width="60px">
<col width="100px">
<col width="150px">
<col width="200px">
<col width="100px">
<col width="120px">
</colgroup>
<thead>
<tr>
<th scope="row">์๋ฒ</th>
<th scope="row">์ฌ์๋ช
</th>
<th scope="row">์ง๊ธ</th>
<th scope="row">์ง์ฑ
</th>
<th scope="row">์ ํ๋ฒํธ</th>
<th scope="row">์ด๋ฉ์ผ</th>
</tr>
</thead>
<!-- <tbody class="center" id="addressbookBody">-->
<tbody class="center">
<tr v-for="item in displayedItems" :key="item.empId">
<td>{{ item.no }}</td>
<td>{{ item.empNm }}</td>
<td>{{ item.positionCd }}</td>
<td>{{ item.roleCd }}</td>
<td>{{ item.empHp }}</td>
<td>{{ item.empEmail }}</td>
</tr>
</tbody>
</table>
<!-- pagination -->
<div class="paging tbl-paging">
<ul class='pagination'>
<li class='paginate_button page-item first'>
<button type='button' class='page-link' style='cursor: pointer;'>
<span class='hidden'>first page</span>
</button>
</li>
</ul>
</div>
</div>
</div>
<div class="popup" id="pop_man">
<a href="#" class="pop-close" id="close" onclick="return false;">
<span class="hidden">ํ์
๋ซ๊ธฐ</span>
</a>
<div class="pop-header">
์ฌ์ ์ ๋ณด
</div>
<form id="updateform">
</form>
</div>
</div>
Vue.js๋ฅผ ์ ์ฉํ thyemeleafํ์ผ์ Vue.js ์ฝ๋ ์ถ๊ฐ(์์)
<!--vue.js start-->
<script>
new Vue({
el: '#app',
data: {
items: [],
currentPage: 1,
totalPageCount: 0,
empNm: '',
},
//๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ณ๊ฒฝํ ์์ฑ
computed: {
displayedItems() {
return this.items;
}
},
mounted() {
this.fetchData();
},
methods: {
//๋ฐ์ดํฐ ์กฐํ
fetchData() {
const url = '/api/user/addressbook';
//2๋ฒ ์งธ parameter(queryString)
const params = { params:
{ currentPage: this.currentPage,
empNm: this.empNm
}
};
axios.get(url, params)
.then(function(response) {
this.items = response.data.list;
this.totalPageCount = response.data.paging.totalPageCount;
console.log(response);
}.bind(this))
.catch(function(error) {
// ์๋ฌ ์ฒ๋ฆฌ
console.log(error);
});
},
//๊ฒ์
searchByName() {
this.currentPage = 1;
this.fetchData();
}
}
});
</script>
<!--vue.js end-->
'IT > development' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JavaScript] ์์ ํ์ ์ฐฝ์์ ๋ถ๋ชจ์ฐฝ์ ํจ์ ํธ์ถ(javascript ์์ฃผ) (0) | 2023.08.13 |
---|---|
[springBoot] ์๋ก ๋ค๋ฅธ branch๋ฅผ ๋์์ ๋์ฐ๋ ค๋ฉด? (0) | 2023.08.12 |
[Vue.js] ์ฝ๋ฐฑ ํจ์์์ this ์ฌ์ฉ ์ ์ ์์ (2) | 2023.08.10 |
[Vue.js] ํ์ด์ง๋ค์ด์ ์ฒ๋ฆฌ (0) | 2023.08.09 |
[Vue.js] modal์ฐฝ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ ์๋ ๋ (2) | 2023.08.06 |
๋๊ธ