利用mounted函数获取最新数据

核心代码:

       mounted(){
			this.str='你好 世界'
			
			this.$nextTick(function(){
				console.log(this.$refs.tit.innerHTML)
			})
			
			
			
       }

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
	<div id="out">
		<h2>最新dom</h2>
		<p ref="tit">{{str}}</p>
		
	</div>
</body>
<script type="text/javascript">
	
	
	var vm=new Vue({
		el:'#out',
		data:{
			str:'hello world'
		},
		mounted(){
			this.str='你好 世界'
			
			this.$nextTick(function(){
				console.log(this.$refs.tit.innerHTML)
			})
			
			
			
		}
	})

 

Logo

前往低代码交流专区

更多推荐