vue方法先后顺序。等A方法运行结束才能触发B方法。cdn引入vue.js(先后顺序)
主要靠watch:{}
<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>