<input type="text" v-model="msg"> {{msg}}
###v-on 事件 <div id="box"> <button v-on:click="say">按钮</button> <button @click="say">按钮</button> </div> <script> new Vue({ el: "#box", data(){ return {} }, methods: { say() { alert(111); } } }) </script>
<div id="box"> <div v-html="msg"></div> </div> <script> new Vue({ el: "#box", data(){ return { msg:"<h1>121212</h1>" } }, methods: { say() { } } }) </script>
<style> .red { background: red; } .blue { width: 100px; height: 100px; background: blue; } </style> <div id="box"> <div style="width: 100px;height: 100px;" v-bind:class='{red:isred}'></div> <!--<div style="width: 100px;height: 100px;" v-bind:class='isred?"red":"blue"'></div>--> <!--三元运算符方式--> <!--<div style="width: 100px;height: 100px;" v-bind:class='[{red:"isred"}]'></div>--> </div> <script> new Vue({ el: "#box", data(){ return { isred:false } } }) </script>
<div id="box"> <div v-text="msg"></div> </div> <script> new Vue({ el: "#box", data(){ return { msg:"11111" } }, methods: { say() { alert(111); } } }) </script>
<div id="box"> <div style="width: 100px;height: 100px;background: black;display: none" v-show="show"></div> </div> </body> <script> new Vue({ el: "#box", data(){ return { show: true } } }) </script>
<div id="box"> <div style="width: 100px;height: 100px;background: black;" v-if="show"></div> </div> <script> new Vue({ el: "#box", data(){ return { show: true } } }) </script>
<div id="box"> <div style="width: 100px;height: 100px;background: black;" v-if="show"></div> <div style="width: 300px;height: 300px;background: blue" v-else=""></div> </div> <script> new Vue({ el: "#box", data(){ return { show: true } } }) </script>
<div id="box"> <div style="width: 100px;height: 100px;background: black;" v-if="show"></div> <div style="width: 100px;height: 100px;background: aqua;" v-else-if=""></div> <div style="width: 300px;height: 300px;background: blue" v-else=""></div> </div> <script> new Vue({ el: "#box", data(){ return { show: true } } }) </script>
<div id="box"> <input type="text" v-bind:value="msg"> <a :href="link">点击</a> </div> <script> new Vue({ el: "#box", data(){ return { msg: "12222", link:"一、v-model.html" } } }) </script>
<div id="box"> <!-- v-on --> <button v-on:click="say">按钮</button> <!--<button @click="say">按钮</button>--> </div> <script> new Vue({ el: "#box", data(){ return {} }, methods: { say() { alert(111); } } }) </script>
<div id="box"> <div v-once>{{msg}}</div> </div> <script type="text/javascript"> new Vue({ el:"#box", data(){ return{ msg:"qwdqwdqwd" } } }) </script>
<div id="box"> <div v-cloak="">欢迎--{{msg}}</div> </div> <script> new Vue({ el:"#box", data(){ return{ msg:"111111" } } }) </script>
<div id="box"> <div v-pre>欢迎--{{msg}}</div> </div> <script> new Vue({ el:"#box", data(){ return{ msg:"111111" } } }) </script>
Vue简介javascript
特色: mvvm m=mvc module 模型 v=view 视图 c=controller 控制器 mvvm m=mvc module 模型 v=view 视图 vm (视图与数据之间的传递) vue1 双向数据绑定 vue2 单向数据流 单页面应用 v-model 数据绑定 data 返回对象用 return v-for 循环 格式 v-for="字段名 in(of) 数组json" v-show 显示 隐藏 传递的值为布尔值 true false 默认为false v-if 显示与隐藏 和v-show对比的区别 就是是否删除dom节点 默认值为false v-else-if 必须和v-if连用 v-else 必须和v-if连用 不能单独使用 不然报错 模板编译错误 v-bind 动态绑定 做用: 及时对页面的数据进行更改 v-on 绑定事件 函数必须写在methods里面 @click 快捷方法 v-text 解析文本 v-html 解析html标签 v-bind:class 三种绑定方法 一、对象型 '{red:isred}' 二、三目型 'isred?"red":"blue"' 三、数组型 '[{red:"isred"},{blue:"isblue"}]' v-once 进入页面时 只渲染一次 不在进行渲染 v-cloak 防止闪烁 v-pre 把标签内部的元素原位输出