本文共 3257 字,大约阅读时间需要 10 分钟。
Vue:渐进式JavaScript框架
声明式渲染→组件系统→客户端路由→集中式状态管理→项目构建 官网:https://cn.vuejs.org/v2/guide/ 最全的学习方法是在官网哦。使用是要引用vue.js文件
原生js
jQuery
Vue
{ { msg}}

把数据填充到HTML标签中
2. 前端渲染方式 ⚫原生js拼接字符串 ⚫ 使用前端模板引擎 ⚫ 使用vue特有的模板语法 3.模板语法概览
⚫差值表达式 ⚫ 指令 ⚫ 事件绑定 ⚫ 属性绑定 ⚫ 样式绑定 ⚫ 分支循环结构{ { msg}}
{ { msg}}//Hello Vue //HTML
//HTML(html编写后的){ { msg}}//{ {msg}}
<input type='text' v-model='uname'/>
{ { msg}}
效果图:
<input type=‘button' v-on:click='num++'/> <input type=‘button' @click='num++'/><button v-on:click='say'>Hello</button> <button v-on:click='say()'>Say hi</button>效果图:
3. 事件函数参数传递 ⚫ 普通参数和事件对象 <button v-on:click='say("hi",$event)'>Say hi</button> 效果图
4. 事件修饰符 ⚫ .stop 阻止冒泡 ⚫ .prevent 阻止默认行为 <a v-on:click.stop="handle">跳转</a> <a v-on:click.prevent="handle">跳转</a> 5. 按键修饰符 ⚫ .enter 回车键 ⚫ .esc 退出键 <input v-on:keyup.enter='submit'> <input v-on:keyup.delete='handle'> <a v-bind:href='url'>跳转</a> <a :href='url'>跳转<div v-bind:class="{ active: isActive }"></div> ⚫ 数组语法 <div v-bind:class="[activeClass, errorClass]"></div><div v-bind:style="{ color: activeColor, fontSize: fontSize }"></div> ⚫ 数组语法 <div v-bind:style="[baseStyles, overridingStyles]"></div>测试样式
<li v-for='item in list'>{ {item}}</li> <li v-for='(item,index) in list'>{ {item}} + '---' +{ {index}}</li> ⚫ key的作用:帮助Vue区分不同的元素,从而提高性能 <li :key='item.id' v-for='(item,index) in list'>{ {item}} + '---' { {index}}</li>水果列表
<div v-for='(value, key, index) in object'></div> <div v-if='value==12' v-for='(value, key, index) in object'></div>{ { v + '---' + k + '---' + i}}
转载地址:http://baah.baihongyu.com/