Correction status:qualified
Teacher's comments:
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>
点击 "运行实例" 按钮查看在线实