sergAccount

Untitled

Sep 29th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.87 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Hello Vue</title>
  5.     <meta charset="utf-8">
  6.     <!-- https://unpkg.com/vue@2.6.11/dist/vue.min.js -->
  7.     <!-- подключение фреймворка vue.js -->
  8.     <script type="text/javascript" src="https://unpkg.com/vue"></script>
  9.     <style type="text/css">
  10.     .active {
  11.       color: red
  12.     }
  13.     .some {
  14.       font-size: 24px;
  15.     }    
  16.     </style>
  17. </head>
  18. <body>
  19. <!-- элемент div c идентификатором app -->
  20. <!-- v-for -->
  21. <div id="app">       
  22.      <input type="number" v-model="price" />
  23.      {{bonus2}}
  24.      <br>
  25.      {{result}}
  26. </div>
  27. </body>
  28. <script type="text/javascript">
  29.     // создаем объект Vue (экземпляр Vue)
  30.     new Vue({
  31.   el: "#app",
  32.   data: {    
  33.     result: '',
  34.     price: 10,
  35.     bonus2: 2,
  36.     products: [
  37.       {name: "Product1", price: 100},
  38.       {name: "Product2", price: 200}
  39.     ]
  40.   },
  41.   watch: {
  42.     price: function(val, oldValue){
  43.        console.log('currentValue=' + val);
  44.        console.log('oldValue='   + oldValue);
  45.        console.log('bonus2=' + this.bonus2);
  46.        this.bonus2 = val * 10;
  47.        //
  48.        this.result = 'Выполнение задачи...';
  49.        var vm = this;
  50.        // задержка 5 секунд
  51.        setTimeout(function(){
  52.           vm.result = 'Процесс завершен';
  53.        }, 5000);
  54.     }
  55.    
  56.   },  
  57.   computed:{
  58.     bonus: function(){
  59.       return this.price * 0.2;
  60.     }
  61.   },    
  62.   methods : {
  63.       buttonclicked : function() {
  64.         console.log('buttonclicked');
  65.       },
  66.       clickme : function(param){
  67.         console.log('clickme=' + param);
  68.       },
  69.       changebgcolor : function() {
  70.           this.styleobj.backgroundColor = "green";
  71.       },
  72.       originalcolor : function() {
  73.           this.styleobj.backgroundColor = "red";
  74.       }
  75.   }
  76. })
  77. </script>
  78. </html>
Add Comment
Please, Sign In to add comment