Last active
December 12, 2015 16:27
-
-
Save nasum/ca5af46e01ca2cf57c9c to your computer and use it in GitHub Desktop.
Vue.jsで作るタグ入力フォーム ref: http://qiita.com/tomato360/items/48ffd92921e8528dad35
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
<div class="text-area"> | |
<div class="tag-list"> | |
<span class="tag" v-for="tag in tags"> | |
{{tag.name}} | |
<span class="delete" v-on:click="delete(this)">x</span> | |
</span> | |
</div> | |
<div class="input-area" contenteditable=true v-on:keydown.enter="decide_tag"> | |
</div> | |
</div> |
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
.text-area{ | |
width: auto; | |
height: 20px; | |
background: white; | |
} | |
.tag-list{ | |
display: inline-block; | |
margin-top: 0px; | |
} | |
.input-area{ | |
display: inline-block; | |
width: 100px; | |
height: 20px; | |
background: white; | |
&:focus{ | |
outline: 0; | |
} | |
} | |
.tag { | |
padding: 2px; | |
background: yellow; | |
} | |
.delete { | |
cursor: pointer; | |
} |
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
$(document).ready(function() { | |
var tag = new Vue({ | |
el: ".text-area", | |
data: { | |
tags: [] | |
}, | |
methods: { | |
decide_tag: function(e) { | |
this.tags.push({ | |
name: e.target.textContent | |
}); | |
e.target.textContent = ""; | |
}, | |
delete: function(vm) { | |
this.tags.splice(vm.$index,1); | |
} | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment