<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>天气案例</title>
<!-- 引入Vue -->
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- 准备一个容器 -->
<div id="root">
<h2>今天天气很{{info}}</h2>
<!-- 绑定事件的时候:@xxx:"yyy" yyy可以写一些简单的语句 -->
<button @click="ishot=!ishot">切换天气</button>
<button @click="changeweather">切换天气</button>
</div>
<script type="text/javascript">
Vue.config.productionTip=false
new Vue({
el:'#root',
data:{
ishot:true
},
computed:{
info(){
return this.ishot?'hot':'cool'
}
},
methods:{
changeweather(){
this.ishot=!this.ishot
}
}
})
</script>
</body>
</html>
vue学习笔记(16)——天气案例
最新推荐文章于 2023-10-17 23:26:13 发布