天气案例:简单实现
<body>
<!-- 准备好一个盒子 -->
<div id="root">
<h2>今天天气很{{isHot ? '热' : '凉爽'}}</h2>
<button>切换天气</button>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = true
new Vue({
el:'#root',
data:{
isHot:true
}
})
</script>
天气案例二:
<body>
<!-- 准备好一个盒子 -->
<div id="root">
<h2>今天天气很{{info}}</h2>
<button @click="changWeather">切换天气</button>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = true
new Vue({
el:'#root',
data:{
isHot:true
},
computed:{
info(){
return this.isHot ? '阳热' :'凉爽'
}
},
methods:{
changWeather(){
this.isHot = !this.isHot
}
}
})
</script>
天气案例三(简写):
<body>
<!-- 准备好一个盒子 -->
<div id="root">
<h2>今天天气很{{info}}</h2>
<button @click="isHot = !isHot">切换天气</button>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = true
new Vue({
el:'#root',
data:{
isHot:true
},
computed:{
info(){
return this.isHot ? '阳热' :'凉爽'
}
},
methods:{
// changWeather(){
// this.isHot = !this.isHot
// }
}
})
</script>
天气案例4(总结):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>天气案例</title>
<!-- 引入vue -->
<script src="../js/vue.js" type="text/javascript"></script>
</head>
<body>
<!-- 准备好一个盒子 -->
<div id="root">
<h2>今天天气很{{info}},{{x}}</h2>
<!--绑定事件的事件时侯 @xxx='yyy'yyy可以写一些语句 -->
<button @click="isHot = !isHot;x++">切换天气</button>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = true
new Vue({
el:'#root',
data:{
isHot:true,
x:1
},
computed:{
info(){
return this.isHot ? '阳热' :'凉爽'
}
},
methods:{
// changWeather(){
// this.isHot = !this.isHot
// this.x++
// }
}
})
</script>
</html>