10/16,17
Vueインフラストラクチャコースの復習
- ref : https://www.inflearn.com/course/vuejs/
*ボードの作成
=>Apiは、サーバーにデータを転送し、サーバーから基板リストのデータを呼び出して画面をレンダリングします.
* Modal.vue構成部品の作成
名前付きSlot
:親構成部品のテンプレートは、子構成部品のSlotがより明確に一致するように使用されます.
//Modal.vue
<div class="modal-container">
<div class="modal-header">
<slot name="header">
default header
</slot>
</div>
<div class="modal-body">
<slot name="body">
default body
</slot>
</div>
<div class="modal-footer">
<slot name="footer">
default footer
<button class="modal-default-button" @click="$emit('close')">
OK
</button>
</slot>
</div>
</div>
<Modal>
<div slot="header">
<h2>
Create new board
<a href="" class="modal-default-button"
@click.prevent="SET_IS_ADD_BOARD(false)">×</a>
</h2>
</div>
<div slot="body">
<form id="add-board-form"
@submit.prevent="addBoard">
<input class="form-control" type="text" v-model="input" ref="input">
</form>
</div>
<div slot="footer">
<button class="btn" :class="{'btn-success': valid}" type="submit"
form="add-board-form" :disabled="!valid">
Create Board</button>
</div>
</Modal>
:親コンポーネントのラベルslotプロパティの値は、サブコンポーネントのslotラベルのnameプロパティと同じ部分で置き換えられます.: AddBoard.Vueの
<div slot="header">
はModelです.vueの<slot name="header"></slot>을 대체해서 렌더링된다.
* Vue Store
-Storeを無効にする
データ抽出ロジック、
//Homde.vue
data() {
return {
boards : [],
}
}
-Storeを使用する場合
AddBoard素子から直接基板を作成した後、Storeに登録されているactionsに登録されている方法で基板データを直接取得できます.
Store管理設定がAddBoardのデータを表示するかどうかも切り替えやすい.
mapState, mapGetters, mapActions, mapMutations
:storeのプロパティを簡単にインポートできます.
オブジェクト展開演算子を使用してリポジトリを使用する理由
//Homde.vue
//1. vuex의 속성들을 import 한다.
import { mapState, mapActions, mapMutations } from "vuex";
//2. 객체 전개 연산자를 이용해 속성을 가져온다.
computed: {
...mapState(["boards", "showAddBoard"]),
},
methods: {
...mapMutations(["SET_IS_ADD_BOARD"]),
...mapActions(["FETCH_BOARDS"]),
fetchData() {
this.isLoading = true;
this.FETCH_BOARDS().then(() => (this.isLoading = false));
},
onCreateBoard() {
this.showAddBoard = false;
this.fetchData();
},
},
//1. commit => mutations
this.$store.commit("LOGIN", token);
//2. dispatch => actions
//2.1 mapActions에 등록되어있을 경우, this를 통해서 접근이 가능
this.FETCH_BOARDS().then(() => (this.isLoading = false));
//2.2 Vue인스턴스에서 $store를 통해서 store에 접근할 수 있고, dispatch()를 이용해서 actions에 등록된 메서드를 사용한다.
this.$store
.dispatch("FETCH_BOARDS")
.then(() => (this.isLoading = false));
*モードウィンドウにEscキーを入力し、クリックして消去します。
//AddBoard.vue
mounted() {
//0.
this.$refs.boardTitle.focus();
//1.
this.setKeyupEvent();
this.setClickcOutSideEvent();
},
methods : {
//2.
setKeyupEvent() {
const self = this;
window.onkeyup = function(e) {
if (e.keyCode !== KEYCODE.esc) return;
self.SET_IS_ADD_BOARD(false);
window.onkeyup = null;
};
},
//3.
setClickcOutSideEvent() {
const self = this;
window.onclick = function(e) {
const $target = e.target;
if ($target.className === "modal-wrapper") {
self.SET_IS_ADD_BOARD(false);
window.onclick = null;
}
};
},
}
//utils/constants.js
export const KEYCODE = {
esc: 27,
enter: 13,
};
*エラー処理
//api/index.js
const NOTFOUND = 404;
//noNotFound()
const noNotFound = () => {
alert("존재하지 않는 보드입니다.");
router.push("/");
};
//Axios Wrapping 함수
const request = (method, url, data) => {
return axios({
method,
url: DOMAIN + url,
data,
})
.then((result) => result.data)
.catch((result) => {
const { status } = result.response;
if (status === UNAUTHROZIED) {
onUnauthorized();
} else if (status === NOTFOUND) {
noNotFound();
}
throw result.response;
});
};
=>404エラー
CSS
:root {
--black-color : #000;
}
var(--black-color);
flex-shrink : 1 //컨테이너의 크기에 반응하여 작아진다.
flex-shrink : 0 //컨테이너 크기에 관계없이 크기를 유지한다.
* Javascript
1.Elliment幅を求める
: https://stackoverflow.com/questions/294250/how-do-i-retrieve-an-html-elements-actual-width-and-height
=> element.offsetWidth;
2.エンベロープ位置、左に移動
正常動作:
$("#wrapper").style.left = "-1200px"
正常動作2:$("#wrapper").style.left = -2400 + "px"
動作X:$("#wrapper").style.left = -1200
3.シンボル変換translateを変更する
:
$wrapper.style.transform = "translate(x, y)";
4. event.target Vs event.currentTarget
: event.target=>イベントのエンティティの実行
: event.CurrentTarget=>イベントをバインドするオブジェクト
Reference
Reference
この問題について(10/16,17), 我々は、より多くの情報をここで見つけました https://velog.io/@kyh196201/1016テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol