• vue-随笔-computed.watch


    基本的demo:

    <!-- /**  
     * @Author: cyany_blue  
     * @Date:   2018-05-29 22:14:19  
     * @Last Modified by:   cyany_blue  
     * @Last Modified time: 2018-05-29 22:19:51  
     */ -->  
    <!DOCTYPE html>  
    <html lang="en">  
    <head>  
        <meta charset="UTF-8">  
        <title>Document</title>  
    	  <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.js"></script>
    </head>  
    <body>  
       <div id="app">
       		<input type="text" v-model="a">
       		<input type="text" v-model="b">
       		<p>{{a}}----{{b}}</p>
       		<p>{{c}}</p>
       </div>
    </body>  
    <script>  
       new Vue({
       		el:'#app',
       		data:{
       			a:'',
       			b:'',
                    //此时这里是不可以初始化赋值c的,切记!!!
       		},
       		computed:{
       			c:function(){
       				// this指的是vm实例
       				return this.a+this.b
       			}
       		},
       		methods:{
    
       		}
       })
    </script>  
    </html>  
    
    <!-- /**  
     * @Author: cyany_blue  
     * @Date:   2018-05-29 22:14:19  
     * @Last Modified by:   cyany_blue  
     * @Last Modified time: 2018-05-29 22:49:05  
     */ -->  
    <!DOCTYPE html>  
    <html lang="en">  
    <head>  
        <meta charset="UTF-8">  
        <title>Document</title>  
    	  <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.js"></script>
    </head>  
    <body>  
       <div id="app">
       		<input type="text" v-model="a">
       		<input type="text" v-model="b">
       		<p>{{a}}----{{b}}</p>
       		<input type="text" v-model="c">
       		<hr>
       		<input type="text" v-model="e">
       		<p>{{e+a}}</p>
       </div>
    </body>  
    <script>  
       new Vue({
       		el:'#app',
       		data:{
       			a:'',
       			b:'',
       			e:''
       		},
       		watch:{
       			e:function(val){
       				this.abc(); 只要e的值一改变,就会触发abc方法
       			}
       		},
       		computed:{
       			// c:function(){
       			// 	// this指的是vm实例
       			// 	return this.a+this.b
       			// }
       			c:{
       				get:function(){
       					return this.a+this.b;
       				},
       				set:function(newVal){
       					var names = newVal.split('');
       					this.a = names[0];
       					this.b = names[1];
       				}
       			}
       		},
       		methods:{
       			abc:function(){
       				console.log('haha')
       			}
       		}
       })
    </script>  
    </html>  
    
  • 相关阅读:
    [算法题] 汉诺塔问题
    ubuntu导入torch模块报错
    深度问答之提取语料2
    深度问答之提取语料,导入了yml模块
    python读取文件存到excel中
    zipfile.BadZipFile: File is not a zip file
    查看linux系统时间
    tensorflow:typeerror:‘noneType’ object is not callable
    正则匹配中文标点符号
    re.sub用法
  • 原文地址:https://www.cnblogs.com/cyany/p/9108409.html
Copyright © 2020-2023  润新知