- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) > JavaScript >
- vue簡(jiǎn)易記事本開(kāi)發(fā)詳解
本文實(shí)例為大家分享了vue實(shí)現易記事本的具體代碼,供大家參考,具體內容如下
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="./css/index.css" > <script src="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="請輸入任務(wù)"> <button @click="add">添加</button> </div> <div class="content"> <ul class="todolist" v-for="(item,index) in list"> <div class="todo"> <span class="index">{{index+1}}</span><label class="list">{{item}}</label><button class="btn" @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>
運行效果截圖
以上就是本文的全部?jì)热?,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站