Created
July 1, 2015 14:01
Vue.jsのv-transitionの使い方
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
<!doctype html> | |
<html lang="ja"> | |
<head> | |
<meta chraset="utf-8"> | |
<title>ファイル出力</title> | |
<link href="style.css" rel="stylesheet" type="text/css"> | |
</head> | |
<body> | |
<div id="transition-demo"> | |
<input type="text" v-model="input | validator" /> | |
<p class="success" v-if="validationInput" v-transition="input">入力値:{{input}} OKです!</p> | |
<p class="error" v-if="!validationInput" v-transition="input">入力値:{{input}} ダメです!</p> | |
</div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/0.12.1/vue.min.js"></script> | |
<script src="index.js"></script> | |
</body> | |
</html> |
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
new Vue({ | |
el: '#transition-demo', | |
data: { | |
input: '', | |
validationInput: false | |
}, | |
filters: { | |
validator: function(value) { | |
if (value.length > 4) { | |
this.validationInput = true; | |
} else { | |
this.validationInput = false; | |
} | |
return value; | |
} | |
} | |
}); |
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
@charset "UTF-8"; | |
.success { | |
color: green; | |
} | |
.error { | |
color: red; | |
} | |
/* v-transitionでは以下のスタイルが適用される */ | |
.input-transition { | |
transition: all .3s ease; | |
height: 30px; | |
padding: 10px; | |
background-color: #eee; | |
overflow: hidden; | |
} | |
.input-enter, .input-leave { | |
height: 0; | |
padding: 0 10px; | |
opacity: 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment