有一個問題,我發(fā)現(xiàn)如果input框里什么也不輸入時點擊提交仍然能創(chuàng)建一個空的li出來,請問怎么能檢測如果input中的值為空不創(chuàng)建li呢
<div class="root">
<input v-model="inputValue" />
<button @click="handle">提交</button>
<input type="button" @click="del" value="刪除" />
<ul>
<li v-for="(item,index) of list" :key = item>{{item}}</li>
</ul>
</div>
<script>
new Vue({
el:'.root',
data:{
inputValue:'',
list:[]
},
methods:{
handle:function(){
this.list.push(this.inputValue);
this.inputValue = '';
},
del:function(){
this.list.pop(this.inputValue);
}
}
})
</script>
2018-10-06
2018-09-25
如何讓列表為空不顯示列表,如果沒有判斷,會有一個空列表
2018-09-14
在this.list.push(this.inputValue);加一個if(this.inputValue!="")判斷就行了