La secuencia de métodos vue. Espere a que el método A termine de ejecutarse antes de activar el método B. cdn presenta vue.js (en secuencia)

La secuencia de métodos vue. Espere a que el método A termine de ejecutarse antes de activar el método B. cdn presenta vue.js (en secuencia)

Confiar principalmente en el reloj: {}

<script>
		   new Vue({
		      el: '#app',
		      data: function() {
		        return { 
					shopListDataAAA:{},
					shopListDataBBB:{},
				}
		      },
			  watch:{
				  shopListDataAAA(){
					  //shopListDataAAA有数据了,再触发下面的方法
					  this.$nextTick(function() {
					  	this.B();//B方法
					  });
				  }
			  },
			  methods:{
				  A(){
					  var that = this;
					  $.ajax({
					  	url: publicFace + 'aaaa/aaaa',
					  	method: 'POST',
					  	success: function(res) {
					  		console.log("详情a", res)
					  		that.shopListDataAAA = res.list;
					  	},
					  	error: function(error) {
					  		console.error('error:', error);
					  	}
					  });
				  },
				  B(){
					  var that = this;
					  $.ajax({
					  	url: publicFace + 'bbbb/bbbb',
					  	method: 'POST',
					  	success: function(res) {
					  		console.log("详情b", res)
					  		that.shopListDataBBB = res.list;
					  	},
					  	error: function(error) {
					  		console.error('error:', error);
					  	}
					  });
				  }
			  }
			  mounted(){
				  this.A();//运行A方法。
			  }
		    })
	</script>

Supongo que te gusta

Origin blog.csdn.net/weixin_44856917/article/details/131069656
Recomendado
Clasificación