Last active
March 21, 2019 09:08
-
-
Save simics-ja/a7c1426e3f92d4ac95f420d9a31851c8 to your computer and use it in GitHub Desktop.
[Vue.jsの基本ディレクティブまとめ] JS Fiddleで動作確認だ! #vuejs
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
<body> | |
<div id="app"> | |
{{ message }} | |
</div> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> | |
</body> |
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
var app = new Vue({ | |
el: '#app', | |
data: { | |
message: 'Hello World!' | |
} | |
}) |
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
<body> | |
<div id="app"> | |
<!-- | |
この書き方はできないのでv-bindを使う. | |
<a href="{{url}}">Vue.js</a> | |
--> | |
<a v-bind:href="url">Vue.js</a> | |
</div> | |
</body> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> |
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
var app = new Vue({ | |
el: '#app', | |
data: { | |
url: 'https://jp.vuejs.org' | |
} | |
}) |
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
<body> | |
<div id="app"> | |
<!-- v-ifを使うとスイッチするたびにDOM要素ごと書き換わるので,頻繁なスイッチには向かない. --> | |
<p v-if="toggle"> | |
Hello | |
</p> | |
<p v-else> | |
No message | |
</p> | |
<hr /> | |
<p v-if="type === 'A'"> | |
Type = A | |
</p> | |
<p v-else-if="type === 'B'"> | |
Type = B | |
</p> | |
<p v-else> | |
Ohter type | |
</p> | |
</div> | |
</body> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> |
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
var app = new Vue({ | |
el: '#app', | |
data: { | |
toggle: false, | |
type: 'B' | |
} | |
}) |
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
<body> | |
<div id="app"> | |
<!-- v-showはCSSのdisplayプロパティでスイッチするので,v-ifより処理が軽い. --> | |
<p v-show="toggle"> | |
{{ message }} | |
</p> | |
</div> | |
</body> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> |
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
var app = new Vue({ | |
el: '#app', | |
data: { | |
toggle: false, | |
message: 'Hello' | |
} | |
}) |
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
<body> | |
<div id="app"> | |
<ol> | |
<li v-for="shout in shouts">{{ shout }}</li> | |
</ol> | |
</div> | |
</body> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> |
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
var app = new Vue({ | |
el: '#app', | |
data: { | |
shouts: ['way', 'wayway', 'yeah'] | |
} | |
}) |
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
<body> | |
<div id="app"> | |
<button v-on:click="onclick"> | |
Click me! | |
</button> | |
<p v-show="toggle"> | |
Hello | |
</p> | |
</div> | |
</body> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> |
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
var app = new Vue({ | |
el: '#app', | |
data: { | |
toggle: false, | |
}, | |
methods: { | |
onclick: function() { | |
this.toggle = !this.toggle; | |
} | |
} | |
}) |
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
<body> | |
<div id="app"> | |
<!-- dataオブジェクトを媒介して片方のinputを書き換えるともう一方の中身も書き換えられる --> | |
<p> | |
<input type="text" v-model="message"> | |
</p> | |
<p> | |
<input type="text" v-model="message"> | |
</p> | |
<pre>{{ $data }}</pre> | |
</div> | |
</body> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> |
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
var app = new Vue({ | |
el: '#app', | |
data: { | |
message: 'Hello', | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment