Skip to content

Instantly share code, notes, and snippets.

@nasum
Last active December 12, 2015 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasum/ca5af46e01ca2cf57c9c to your computer and use it in GitHub Desktop.
Save nasum/ca5af46e01ca2cf57c9c to your computer and use it in GitHub Desktop.
Vue.jsで作るタグ入力フォーム ref: http://qiita.com/tomato360/items/48ffd92921e8528dad35
<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>
.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;
}
$(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