<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- 引入vue -->
<script type="text/javascript" src="../vue.js"></script>
</head>
<body>
<div id="root">
<h2>今天天气很{{info}}</h2>
<!-- 绑定事件的时候:@xxx=“yyy" yyy可以写一些简单的语句 -->
<button @click="changeweather">切换天气</button>
</div>
</body>
<script type="text/javascript">
const vm = new Vue({
el:'#root',
data:{
isHot:true
},
computed:{
info(){
return this.isHot ?'炎热':'凉爽'
}
},
methods:{
changeweather(){
this.isHot = !this.isHot
},
}
})</script>
</html>
Vue天气案例
最新推荐文章于 2024-04-04 18:50:50 发布