<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
</head>
<body>
<div id="app">
{{ag}}---------{{fanzhuan}}-----------{{fan()}}
<hr />
{{h}}<button @click="denglu()">登录</button>
<hr />
今天的温度是:{{weidu}}℃
衣服:{{yifu}}
<br />
<button @click="add()">升温</button>
<button @click="res()">降温</button>
</div>
</body>
<script type="text/javascript">
var app=new Vue({
el:'#app',
data:{
ag:'hellow',
count:0,
weidu:15,
yifu:"衬衫",
},
/*计算属性*/
computed:{
fanzhuan:function(){
return this.ag.split('').reverse().join('');/* split 分割字符串 reverse 反转 join 再次组成字符串*/
},
h:function(){
return this.count==1?"已登录":"未登陆";//判断count是否为1
},
},
/*方法*/
methods:{
fan:function(){
return this.ag.split('').reverse().join('');
},
/*fanzhuan和fan 一样 一个是方法一个是计算属性*/
denglu:function(){
this.count=1; //登录方法
},
add:function(){
this.weidu+=5;
},
res:function(){
this.weidu-=5;
},
},
watch:{
weidu:function(newval,oldval){
if (newval >20) {
this.yifu="短袖";
}
else if(newval<20 && newval>0){
this.yifu="衬衫";
}
else{
this.yifu="羽绒服";
}
}
}
});
</script>
arryObject.splice(index,count) 删除数组中的值
arryObject.splice(index,0,count) 插入数组
arryObject.splice(index,count,要替换的数组) 替换
arryObject.reverse() 颠倒数组
arryObject.join("隔开符号") 把数组中的所有元素放入一个字符串 (隔开符号不写的话默认为逗号)