Vue入门

<!DOCTYPE html>

<html lang="en"> 

   <head>

         <meta charset="UTF-8">

         <title>example</title>

         <script src="./vue.js"></script>  //导入vue.js

   </head>

   <body>

         <div id="root">

                <input  v-model="firstName"/>    //输入框 ,v-model实现firstName的双向绑定

                 <input v-model="lastName"/>   

                 <div  v-text="fullName"></div>  //v-html="funllName"  输出fullName

                 <div  v-bind:title="this is count">{{count}}</div>   //title: 鼠标点击hint

                  <ul><li v-for="(item,index) of myArr" :key="index">{{item}}</li></ul>   //v-for:循环集合 myArr,得到每一项item

                 <button v-on:click="clickHandle">clickMe</button>   //click事件绑定

                  <div  v-show="show">this info could hid</div>  // v-if 是删除html,v-show仅仅是用display:none.

          </div>

          <script>

                new Vue({    //初始化 vue实例

                     el:"#root",   //el:对应元素ID

                    // template: '',  //元素的显示模板

                     data:{     //实例的数据

                           firstName:'',

                           lastName:'',

                           count:0,

                            show = true;

                            myArr:[1,2,3]

                      },

                      computed:{   //计算字段

                             fullName: function(){

                                   return this.firstName+' '+ this.lastName;

                              }

                      }

                      methods:{   //事件函数

                             clickHandle: function(){

                                   this.show = ! this.show;

                             }

                      },

                      watch:{   //变量changed绑定的函数

                            firstName: function(){

                                  this.count ++;

                             }

                            lastName: function(){

                                 this.count++;

                            }

                      }

                })

          </script>

   </body>

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值