zoukankan      html  css  js  c++  java
  • vue页面自动刷新的问题

    1、 activated (VUE页面自动刷新的问题)

    在项目中遇到需要添加完数据之后跳转到展示页不自动刷新的问题,最开始想到的是created()或者 mounted();没能实现;因为全局vue.js不强制刷新或者重启时只创建一次,也就是说,created()或者mounted()只会触发一次。

    activated():在vue对象存活的情况下,进入当前存在activated()函数的页面时,一进入页面就触发;可用于初始化页面数据等。

    2、watch

    watch :在vue实例化时将会遍历所有属性,然后监听其变化。

    <body>
        <div id="app">
            <input v-model="name"/>
            <span>{{name}}</span>
        </div>
    </body>
    	<script>
    		app = new Vue({
    			el:"#app",
    			data:{
    				name:'1'
    			},
    			watch:{
    				name:function(){
    					console.log("changed");
    					this.show();
    				}
    			},
    			methods:{
    				show(){
    					console.log("show function")
    				}
    			}
    		})
    	</script>
    

    3、computed 计算属性

    computes: 其中的属性不用在data中定义,示例如下:

    <div id="app">
    	<input v-model="name" />
    	<span>{{names}}</span>
    </div>
    
    <script>
    		app = new Vue({
    			el:"#app",
    			data:{
    				name:''
    			},
    			computed:{
    				names:function(){
    					return this.name + "world";
    				}
    			}
    		})
    </script>
    
  • 相关阅读:
    CodeForces 288A Polo the Penguin and Strings (水题)
    CodeForces 289B Polo the Penguin and Matrix (数学,中位数)
    CodeForces 289A Polo the Penguin and Segments (水题)
    CodeForces 540C Ice Cave (BFS)
    网站后台模板
    雅图CAD
    mbps
    WCF学习-协议绑定
    数据库建表经验总结
    资源位置
  • 原文地址:https://www.cnblogs.com/newbest/p/11210244.html
Copyright © 2011-2022 走看看