• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
车车大人
博客园    首页    新随笔    联系   管理     

走进Vue的第二天

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>属性绑定和双向数据绑定、计算属性和侦听器</title>
    <script src="vue.js"></script>
</head>
<body>
    <!--
        绑定属性用  v-bind:属性名="vue实例中的data值"(这其中v-bind:可以缩写成:)
        双向绑定用到的是  v-model
        监听用到的方法是watch,可以实现页面自增
    -->
    <div id="root">
        <div :title="title">Hello Word</div>
        <input type="text" v-model="title">
        <div v-text="title"></div>
    </div>


    <div id="foo">
        姓:<input type="text" v-model="firstName">
        名:<input type="text" v-model="lastName">
        <p>您输入的是:{{fullName}}</p>
        <p>{{count}}</p>
    </div>

    <script>
        new Vue({
            el:"#root",
            data:{
                title : "可变性的title"
            }
        });

        new Vue({
            el:"#foo",
            data:{
                firstName:"",
                lastName:"",
                count:0
            },
            computed:{
                fullName:function () {
                    return this.firstName + this.lastName;
                }
            },
            watch:{
                firstName:function () {
                    this.count++;
                },
                lastName:function () {
                    this.count++;
                }
            }
        });
    </script>

</body>
</html>

 

通往牛逼的路上,在意的只有远方!
posted @ 2019-07-05 19:13  车车大人  阅读(154)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3