美文网首页
simple demo

simple demo

作者: 细密画红 | 来源:发表于2018-11-12 19:24 被阅读10次

    HTML

    <div id="app">
      <button v-on:click="counter++"> Increase </button>
       <button v-on:click="counter--">Decrease</button>
       <button v-on:click="secondCounter++">Increase Second </button>
      <br />
      <span>Counter:{{ counter }}</span>  <br />
        <span>secondCounter:{{ secondCounter }}</span>  <br />
      <span>Result:{{ getResult() }} </span>  <br />
      <pan>OutPut:{{ output }}</span>
     
    </div>
    

    JS

    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>
    <script>
    new Vue({
      el:'#app',
      data:{
        counter:0,
        result:'',
        secondCounter:0,
      },
      computed:{
        output:function(){
          console.log("computed test");
          return this.counter >5 ?'Greater 5':'Smaller than 5';
        }
      },
      watch:{
        counter:function(value){
           var vm = this;
          setTimeout(function(){
           vm .counter =0;
            
          },2000);
        }
      },
      methods:{
        getResult() {
          console.log('test');
          return this.counter >5 ?'Greater 5':'Smaller than 5';
        }
      }
    });
    </script>
    

    相关文章

      网友评论

          本文标题:simple demo

          本文链接:https://www.haomeiwen.com/subject/iukcfqtx.html