Vue2 异步获取的数据(通过ajax)获取的数据 渲染到dom上

页面dom结构如下

  • 姓名: {{msg.name}}
  • 年龄: {{msg.old}}
  •     
  • 地址: {{msg.address}}
  • id: {{msg.user_id}}
  • 删除


  

js

                var app = new Vue({
				el:'#app',
				data:{
					msg:{
						name:'zhangsan',
						old:'18',
						address:'shanghai',
						user_id:'101010',
					}
				},
                   //可以将渲染数据的操作放在
                  //
beforeCreate 、created 、beforeMounted 、 mounted 里面
                  
				beforeCreate:function(){
					var _this = this;
						$.ajax({
							type:"get",
							url:"http://127.0.1:8888",
							async:true,
							success:function(data){
								_this.msg.name = data[0]['name'];
								_this.msg.old = data[0]['age'];
								_this.msg.address = data[0]['address'];
								_this.msg.user_id = data[0]['id'];
							},
							error:function(data){
								
							},
						});
					
				},
				methods:{
					
				},
			});

  

转载于:https://www.cnblogs.com/MainActivity/p/8458791.html

你可能感兴趣的:(Vue2 异步获取的数据(通过ajax)获取的数据 渲染到dom上)