Blogger Information
Blog 35
fans 0
comment 0
visits 32852
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
vue.js基本操作——2018-10-7
THPHP
Original
845 people have browsed it

1、 v-text,v-html变量渲染:

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue.js基本操作</title>
</head>
<body>
<div id="box">
    <p v-text="text"></p>
    <p v-html="html"></p>
</div>
<script src="../lib/js/Vue.js"></script>
<script>
/*  v-text,v-html变量渲染:v-text 不会解析html标签,v-html可以解析html标签 */
    new Vue({
        el:'#box',
        data:{
            text:'<h3>php中文网</h3>',
            html:'<h3>php中文网</h3>'
        }
    });
</script>
</body>
</html>

运行实例 »

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


2、属性绑定v-bind和事件绑定v-on

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue.js基本操作</title>
</head>
<body>
<div id="box">
    <h3 v-bind:style="style" v-on:click="Text">{{htmL}}</h3>
</div>
<script src="../lib/js/Vue.js"></script>
<script>
    new Vue({
        el:'#box',
        data:{
            htmL:'php中文网',
            style:'color:red;'
        },
        methods:{
            Text:function () {
                this.htmL = "www.php.cn";
            }
        }
    });
</script>
</body>
</html>

运行实例 »

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

3、双向数据绑定:

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue.js基本操作</title>
</head>
<body>
<div id="box">
    <input type="text" v-model="info">
    <p>{{info}}</p>
</div>
<script src="../lib/js/Vue.js"></script>
<script>
    new Vue({
        el:'#box',
        data:{
            info:'css'
        }
    });
</script>
</body>
</html>

运行实例 »

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

3、侦听器:

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue.js基本操作</title>
</head>
<body>
<div id="box">
    <input type="text" v-model="user">
    <h3>{{length}}</h3>
    <span v-show="show" v-bind:style="style">{{text}}</span>
</div>
<script src="../lib/js/Vue.js"></script>
<script>
/*  v-text,v-html变量渲染:v-text 不会解析html标签,v-html可以解析html标签 */
    new Vue({
        el:'#box',
        data:{
            user:'',
            length:0,
            show:false,
            style:'color:red;',
            text:'用户名太短'
        },
        watch:{
            user:function () {
                this.length++;
                if(this.length < 6){
                    this.show = true;
                }else {
                    this.show = false;
                }
            }
        }
    });
</script>
</body>
</html>

运行实例 »

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

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post