博主信息
博文 38
粉丝 0
评论 0
访问量 30567
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
第二十八课—Vue.js 2018年9月30日 20时00分
空白
原创
984人浏览过

1.引入Vue.js:使用<script></script>标签导入

2.Vue.js本质是一个构造函数,可以用来创建对象;直接 new Vue()即可使用

3.v-text,v-html变量渲染时的区别

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue v-text,v-html属性</title>
</head>
<body>
<!--创建挂载点-->
<div class="box">
    <!--v-tex仅显示文本-->
    <p v-text="msg1"></p>
    <!--v-html可以解析html标签-->
    <p v-html="msg2"></p>
</div>

<!--导入Vue.js-->
<script src="../Vue.js"></script>
<script>
    // 实例化Vue
    new Vue({
        // 绑定挂载点
        el: '.box',
        data: {
            msg1: 'hello Vue',
            msg2: '<h3 style="color: red">欢迎使用Vue</h3>'
        }
    })
</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

4.属性绑定v-bind和事件绑定v-on

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>属性绑定和事件绑定</title>
</head>
<body>
<div class="box">
    <!--属性绑定v-bind-->
    <p v-bind:style="style">{{msg}}</p>
    <p :style="style">{{msg}}</p>
    <p v-on:click="showDesc">{{msg1}}</p>
    <p @click="changeText">{{msg2}}</p>
</div>

<script src="../Vue.js"></script>
<script>
    new Vue({
        el: '.box',
        data: {
            msg: 'Vue.js',
            style: 'color:red',
            msg1: 'html',
            msg2: 'html'
        },
        methods: {
            showDesc: function () {
                this.msg1 = "JavaScript"
            },
            changeText: function () {
                this.msg2 = 'css'
            }
        }
    })
</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

2-1.png

5.v-model指令实现数据双向绑定

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>v-model指令</title>
</head>
<body>
    <div class="box">
        <input type="text" v-model="info">
        <p>{{info}}</p>
    </div>

<script src="../Vue.js"></script>
<script>
    new Vue({
        el: '.box',
        data: {
            info: 'html'
        }
    })
</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

3.png

6.侦听器

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>侦听器</title>
</head>
<body>
<div class="box">
    用户名:<input type="text" v-model="username">
    <h3>{{length}}</h3>
    <h3 v-show="isShow" :style="style">{{msg}}</h3>
</div>

<script src="../Vue.js"></script>
<script>
    new Vue({
        el: '.box',
        data: {
            username: '',
            length: 0,
            isShown: false,
            style: 'color:red',
            msg: '用户名太短'
        },
        // 监听器
        watch: {
            username: function () {
                this.length++
                if(this.length < 6){
                    this.isShow = true
                } else {
                    this.isShow = false
                }
            }
        }
    })
</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

4.png


批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学