首先需要做的效果:
静态样式
<div id="app"> <h1>当前总数为:{{nbr}}</h1> <select v-model.number="n"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <button @click="add">+</button> <button @click="subtract">-</button> <button @click="odd">为奇数再加</button> <button @click="item">等一等再加</button> </div>
js部分
data(){ return{ n:1, nbr:0, } }, methods:{ add(){ this.nbr += this.n console.log('App',this); }, subtract(){ this.nbr -=this.n }, odd(){ console.log(this.nbr); if (this.nbr % 2 ==1) { this.nbr += this.n } }, item(){ setTimeout(()=>{ this.nbr += this.n console.log(this.nbr); // 时间间隔 },1500); } },
css部分
<style lang="less" scoped> button{ margin-left: 5px; } </style>
标签:vue,console,log,求和,nbr,案例 From: https://www.cnblogs.com/0722tian/p/17147412.html