久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

Vue實現(xiàn)計數(shù)器案例

瀏覽:14日期:2022-09-28 16:09:38

本文實例為大家分享了Vue實現(xiàn)計數(shù)器展示的具體代碼,供大家參考,具體內(nèi)容如下

效果:

Vue實現(xiàn)計數(shù)器案例

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>計數(shù)器</title> <script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'></script> <style type='text/css'> #app{ text-align: center; margin: 0 auto; line-height: 500px; } #app input{ width: 50px; height: 40px; font-size: 20px; border-radius: 5px; outline: none; /* 自定義邊框 */ border: 1px solid transparent; background-color: blue; line-height: 30px; color: white; } #app span{ padding: 20px 20px; border: 1px; } </style></head><body> <div id='app'> <input type='button' value='-' @click='sub'/> <span>{{num}}</span> <input type='button' value='+' @click='add'/> </div> <script>var app = new Vue({ el: '#app', data: {num: 1 }, methods:{add: function(){ if(this.num<10){ this.num++; }else{ alert('達到最大啦!'); } },sub: function(){ if(this.num>0){this.num--; }else{alert('已經(jīng)沒有了!'); } } }}) </script></body></html> data中寫需要用到的數(shù)據(jù): num -methods中添加兩個方法:加(add)、減(sub) 使用v-text或者差值表達式將num設(shè)置給span標簽 使用v-on:(簡寫,@)將addsub分別綁定給+、-按鈕 累加的邏輯:小于10累加,否則提示 遞減的邏輯:大于0遞漸,否則提示 方法中通過this關(guān)鍵字獲取data中的數(shù)據(jù)

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 大英县| 宜君县| 吉安县| 平遥县| 阿克陶县| 左权县| 普兰店市| 海原县| 琼中| 思南县| 永康市| 达孜县| 岳阳县| 崇礼县| 恩平市| 常熟市| 孟村| 辽阳市| 华亭县| 依安县| 揭西县| 长春市| 文安县| 宜丰县| 密山市| 十堰市| 称多县| 鄂温| 玛多县| 正镶白旗| 金湖县| 河津市| 蓝田县| 和田县| 武鸣县| 二手房| 林周县| 包头市| 威远县| 河北区| 奇台县|