Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

vue2 mounted,beforeUpdate,updated问题

父组件传了一个属性,我需要用这个属性发请求,如果把请求放在mounted里就会只执行一次,以后再触发更新,子组件不会重新渲染,如果把请求放在beforeUpdate和updated里 就会无限发请求;

mounted() {

  var vm=this;
  function firstData(){
    vm.$http({
      method:'GET',
    url:''+vm.test,
      emulateJSON: true
    }).then(function(response){
    var dataJson=JSON.stringify(response.data)
    console.log(dataJson)
    vm.tableData=response.data
    }) 
  };
  firstData()
},
beforeUpdate() {
  var vm=this;
  function firstData(){
    vm.$http({
      method:'GET',
    url:'/asp-webapp/entities/ent_Division/findChildren/'+vm.test,
      emulateJSON: true
    }).then(function(response){
    var dataJson=JSON.stringify(response.data)
    console.log(dataJson)
    vm.tableData=response.data
    }) 
  };
  firstData()
},

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

放在watch中


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...