一.vue.js 渐进式的javascript的框架
二.vue的优点
1)体积小,更高的运行效果,双向数据绑定,生态丰富,学习成本低
三.引入vue进行对vue的简单了解
vueDemo
{{age}} {{name}}
鼠标悬停几秒钟查看此处动态绑定的提示信息!
现在你看到我了
{{ todo.text }}
{{ info }}
{{ mess }}
{{addr}}
{{msg}}
using v-html directive:
{{ num +10}}
{{ status ? 'YES' : 'NO' }}
{{ str.split('').reverse().join('') }}
click me
Original str: "{{ string }}"
Computed reversed str: "{{ reversedString }}"
A
B
Not A/B
v-show
{{index}}-{{item.name}}
{{index}}-{{key}}-{{value}}
Message is: {{ mess1 }}
Multiline Message is: {{ mess2 }}
Picked: {{ picked }}
Checked names: {{ checkedNames }}
Selected: {{ selected }}
var app=new Vue({
el:'#app', //指定赋值元素
data:{age:'20',name:'wz'} //赋值元素
});
var app1=new Vue({
el:'#app1', //指定赋值元素
data:{message:'页面加载于'+new Date().toLocaleString()} //赋值元素
});
var app2 = new Vue({
el: '#app2',
data: {seen:false}
});
var app3= new Vue({
el:'#app3',
data:{
todos:[{text:'A'},{text:'B'},{text:'C'}]
}
});
var app4=new Vue({
el:'#app4',
data:{info:'abcde'},
methods:{
upperMessage:function(){
this.info=this.info.toUpperCase()
}
}
});
var app5=new Vue({
el:'#app5',
data:{mess:'ceshi-app5'}
});
var data={addr:'bj'};
//vm(viewmodule)是约定俗称的Vue实例名称
var vm=new Vue({
el:'#app6',
data:data
});
//vue实例属性与方法
vm.$watch('addr',function(newValue,oldValue){
console.log(oldValue,newValue);
})
vm.addr='sh';
//等价于data.addr='sh',vm.$data.addr='sh'
var vm=new Vue({
el:'#app7',
data:{msg:'app7',rawHtml:'this is should be red'}
});
vm.msg='cccc' //v-once:数据改变内容不会发生变化
var vm=new Vue({
el:'#app8',
data:{
color:'red',
url:'http://www.baidu.com',
isActive:false,
isGreen:true,
stylecolor:"#FF0000",
isGray:true,
styleObject:{color:'red',background:'yellow',fontSize:'30px'}
}
});
var vm=new Vue({
el:'#app9',
data:{num:10,status:false,str:'abc'}
});
var vm=new Vue({
el:'#app10',
methods:{
click1:function(){
console.log('click1....');
},
click2:function(){
console.log('click2....')
}
}
});
var vm=new Vue({
el:'#app11',
data:{string:'hello'},
computed:{
reversedString:function(){
return this.string.split('').reverse().join('')
}
}
});
var vm=new Vue({
el:'#app12',
data:{type:'cccc',status_ok:true}
});
var vm=new Vue({
el:'#app13',
data:{
items:[{name:'wz'},{name:'yc'}],
demos:{'fristname':'wang','secondname':'zhen'}
}
});
var vm=new Vue({
el:'#app14',
data:{counter:0},
methods:{
greet:function(str,e){
alert(str),
console.log(e)
}
}
});
var vm=new Vue({
el:"#app15",
data:{
mess1:'',
mess2:'',
picked:'',
checkedNames:[],
selected:''
},
methods:{
submit:function(){
var postObj={
msg1:this.mess1,
msg2:this.mess2,
pick1:this.picked,
check1:this.checkedNames,
select1:this.selected,
};
console.log(postObj);
}
}
});
//组件的调用
Vue.component('button-counter',{
props: ['title'], //定义属性
data:function(){
return {
count:0
}
},//每个组件必须只有一个根元素
template:''
})
var vm=new Vue({
el:'#app16',
data:{}
});
Vue.component('button-click',{
props:['title'],
data: function(){
return {count:0}
},
template:'',
methods:{
clickfun:function(){
this.count ++;
this.$emit('clicknow',this.count);
}
}
})
var vm=new Vue({
el:'#app17',
data:{},
methods:{
clicknow:function(e){
console.log(e);
}
},
components:{//局部注册
test:{
template:'
hello.....
'}
}
});
.blue{color: green;font-size: 20px;}
.red{color: red;font-size: 10px;}
.font-size{font-size: 30px;}
.active{background-color: red;}
.green{color:green;}