:class='[red]' 数据
:class='[red,blue,...]' :cladd="{red:true,blue:true}"
:class:'json' data:{red:true,blue:false}
:style="[c,d]"
data:{ a:{color:'red'}, b:{backgroundColor:'teal'} //复合样式采用驼峰 }:style:"json"
data:{red:true,blue:false}{{msg|filterA}}
{{msg|capitalize}} 首字母大写
{{msg|lowercase|capitalize}} 转小写再首字母大写
{{msg|currency}} $
{{msg|currency '参数'}} 参数+msg
debounce 配合事件使用,延迟执行
@keyup='show() | debounce 1000'数据配合使用过滤器
limitBy 限制个数limitBy 参1(取几个)limitBy 参1(取几个)参2(从哪开始) {{v}} filterBy 过滤数据 {{v}}//搜索
{{v}} orderBy 排序 (1 正序 -1 倒序)get
<input type="button" value='按钮' @click='get()' get:function () { this.$http.get('text1.txt').then(function (data) { alert(data.data); },function (res) { alert(res.status) }) }post
<input type="button" value='按钮' @click='post()' post:function () { this.$http.post('post.php',{ a:3, b:9 },{ emulateJSON:true }).then(function (data) { alert(data.data); },function (res) { alert(res.status) }) }jsonp
<input type="button" value='按钮' @click='jsonp()' jsonp:function () { this.$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',{ wd:'a' },{ jsonp:'cb' //callback名字 默认为callback }).then(function (data) { console.log(data); alert(data.data.s); },function (res) { alert(res.status) }) }合写
this.$http({ url:地址, data:{ method:'get/post/jsonp' jsonp:"cb//cbName" } }) eg:this.$http({ url:URL, data:{ act:'get', page:n } }).then(function (res) {}created:function(){} //实例创建
beforeCompile:fun(){} //编译之前
compile:fun(){} //编译之后
ready: //插入到文档中
beforeDestroy //销毁之前
destroy //销毁之后
var vm= new Vue({
data: { a:'lalal' }}).$mount('#app'); // vm.$mount('#app'); console.log(vm.$el); vm.$el.style.background='red';
console.log(vm.$data.a);
vm.$options.属性 //获取自定义属性 vm.$destroy //销毁属性vm.$log() //查看现在数据的状态Vue.directive(指令名称不要v-,fun(){ }))
eg: Vue.directive('red',function () { //this.el 原生DOM this.el.style.background='red'; })拖拽
Vue.directive("drag",function(){ var div = this.el; div.onmousedown = function(e){ var disX = e.clientX- div.offsetLeft; var disY = e.clientY - div.offsetTop; document.onmousemove = function(e){ var l =e.clientX -disX; var t =e.clientY- disY; div.style.left = l + "px"; div.style.top = t+ "px"; }; document.onmouseup = function(){ document.onmousemove = null; document.onmouseup = null; } } }) window.onload=function(){ var vm=new Vue({ el:'#box', data:{ msg:'welcome' } }); };自定义元素指令:(了解) Vue.elementDirective('ma-red',{ bind:fun(){ this.el.style.color="red'; }
})自定义键盘信息 --@keydown.up @keydown.down 自定义键盘ctrl Vue.directive("on").keyCodes.ctrl=17;
vm.$watch(name,fun(){})) //浅度 var vm=new Vue({ el:'#box', data:{ msg:'welcome', info:'hello' }
}); vm.$watch('msg',function () { alert('变化了'); this.info='haha' }); document.onclick=function () { vm.msg='sb' }vm.$watch(name,fun(){deep:true})) //深度监视
var vm=new Vue({ el:'#box', data:{ msg:{name:'zs',age:18}, info:'hello' } }); vm.$watch('msg',function () { alert('变化了'); this.info='haha' },{deep:true}); document.onclick=function () { vm.msg.name='sb' } <div>{{msg | json}}</div //json过滤器 相当于JSON.stringify --js转换为字符串