You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					48 lines
				
				1.1 KiB
			
		
		
			
		
	
	
					48 lines
				
				1.1 KiB
			| 
											3 years ago
										 | <!DOCTYPE html>
 | ||
|  | <html lang="en">
 | ||
|  | <head>
 | ||
|  |     <meta charset="UTF-8">
 | ||
|  |     <title>2.天气案例_监视属性</title>
 | ||
|  |     <script type="text/javascript" src="../vue.js"></script>
 | ||
|  | </head>
 | ||
|  | <body>
 | ||
|  | <div id="root">
 | ||
|  |     <h3>今天天气很{{showInfo}}</h3>
 | ||
|  |     <button @click="changeWeather">切换天气</button>
 | ||
|  | </div>
 | ||
|  | <script>
 | ||
|  |     Vue.config.productionTip = false
 | ||
|  |     const vm = new Vue({
 | ||
|  |         el: "#root",
 | ||
|  |         data: {
 | ||
|  |             'isHot': true,
 | ||
|  |         },
 | ||
|  |         computed: {
 | ||
|  |             showInfo() {
 | ||
|  |                 return this.isHot ? '炎热' : '凉爽'
 | ||
|  |             }
 | ||
|  | 
 | ||
|  |         },
 | ||
|  |         methods: {
 | ||
|  |             changeWeather() {
 | ||
|  |                 this.isHot = !this.isHot
 | ||
|  |             }
 | ||
|  |         },
 | ||
|  |         // watch: {
 | ||
|  |         //     isHot: {
 | ||
|  |         //         immediate: true,
 | ||
|  |         //         handler(newValue,oldValue){
 | ||
|  |         //             console.log('isHot 被修改', newValue, oldValue)
 | ||
|  |         //         }
 | ||
|  |         //     }
 | ||
|  |         // }
 | ||
|  |     })
 | ||
|  |     vm.$watch('isHot', {
 | ||
|  |         immediate: true,
 | ||
|  |         handler(newValue, oldValue){
 | ||
|  |             console.log('isHot 被修改了', newValue, oldValue)
 | ||
|  |         }
 | ||
|  |     })
 | ||
|  | </script>
 | ||
|  | </body>
 | ||
|  | </html>
 |