vue簡易記事本開發詳解
本文實例為大家分享了vue實現易記事本的具體代碼,供大家參考,具體內容如下
css代碼
#todoapp { margin: 0 400px; width: 600px; background-color: gray; text-align: center;}.content { margin:0px 100px;}.todo { margin: 10px; text-align: left; background-color:green;}.btn { float: right; background-color: lawngreen;}.clear{ background-color: lightseagreen;}.list{ margin-left: 10px;}
html代碼加js代碼
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <title>Document</title> <link rel='stylesheet' href='http://www.wxshucaidpc.com/bcjs/css/index.css' > <script src='http://www.wxshucaidpc.com/bcjs/js/vue.js' type='text/javascript' charset='utf-8'></script></head><body> <div id='todoapp'> <div class='header'><h1>小黑記事本</h1><input type='text' v-model='inputValue' placeholder='請輸入任務'> <button @click='add'>添加</button> </div> <div class='content'><ul v-for='(item,index) in list'> <div class='todo'><span class='index'>{{index+1}}</span><label class='list'>{{item}}</label><button @click='remove(index)'>刪除</button> </div> </ul> </div> <div> <button @click='clearBoth' class='clear'>全部清除</button> </div> </div> <script>var app = new Vue({ el:'#todoapp', data: { list:['吃飯飯','打游戲','吃西瓜'], inputValue:'' }, methods: {remove:function(index){ this.list.splice(index,1)},add: function () { this.list.push(this.inputValue)},clearBoth:function(){ this.list.splice(0,this.list.length)} }}) </script></body></html>
運行效果截圖
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章: